Closed Bug 1418547 Opened 7 years ago Closed 4 years ago

Programmatically inserted inline JS content scripts don't appear in DevTools Debugger

Categories

(DevTools :: Debugger, defect, P3)

58 Branch
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: Mastacheata, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0 Build ID: 20171115114231 Steps to reproduce: Tried to debug a UserScript inserted via Greasemonkey. The problem appears to be more generic though and probably affects any extension that programmatically inserts inline JS code using the chrome.tabs.executeScript WebExtension API. Actual results: The scripts run just fine and you can verify that Greasemonkey runs the chrome.tabs.executeScript function with the UserScripts matching the tab's domain. However in the DevTools Debugger Panel, there's no sign of any content scripts from Greasemonkey at all. Expected results: The Debugger should record dynamically inserted content scripts even if there is no corresponding file for them. Just create dummy file entries if need be, but don't leave us without any chance to debug inline content scripts.
Component: Untriaged → Developer Tools: Debugger
One more thing: If you add a debugger statement into the injected JS code, the debugger will correctly pause execution and will even show the call stack and scope of the injected code. You can't really do any debugging with that, though as the actual code is still missing. The call stack maps the executeScript call to the Script.inject function in resource://gre/modules/ExtensionContent.jsm It then tries to map the inline calls to corresponding lines in the ExtensionContent.jsm offset by the line number where that actually evals the injected code. (i.e.: injected code line 100 becomes line 461 because the ExtensionContent.jsm runs Cu.evalInSandbox on line 361) While I originally assigned this bug to the DevTools Debugger, now I'm no longer sure if this can be solved by the Debugger component or if the problem is actually deeper in the sandboxing mechanism of Firefox.
Added the bug report on GitHub as well: https://github.com/devtools-html/debugger.html/issues/4754
Thanks for filing, I hope to look into this soon
Priority: -- → P2
Product: Firefox → DevTools

From related github issue:
https://github.com/devtools-html/debugger.html/issues/4754

Here's a minimalistic demo extension:
https://github.com/mastacheata/debug-content-scripts-demo-extension
(You'll have to debug the extension for it to stop after creating the tab and then open the debugger for the new tab to see the code injection and have it stop in the injected code)


@Mastacheata: A lot changed since this bug was reported. Is this still an issue?

Honza

Flags: needinfo?(Mastacheata)

A lot changed since this bug was reported. Is this still an issue?

Yes, same issue as before. Breaks in ExtensionContent.jsm instead of the injected contentScript code.

I've adjuested the demo extension to match the current state of the extension API. (apparently the activeTab permission is no longer enough to run background scripts on a tab you opened using the extension and the executeScript function is no longer defaulting to use a string argument as the code)

I've added a screenshot of the problem to the demo repository:
https://github.com/mastacheata/debug-content-scripts-demo-extension/raw/master/problems.png

Flags: needinfo?(Mastacheata)
Blocks: dbg-addon
Priority: P2 → P3

This pauses in the correct script now on Nightly with https://bugzilla.mozilla.org/show_bug.cgi?id=1643540, so I'm going to close this. The source does show in the file tree, which I think is a bug, so I've filed https://bugzilla.mozilla.org/show_bug.cgi?id=1651557 to revisit that.

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.