debugger statement not working in content script
Categories
(DevTools :: Debugger, defect, P2)
Tracking
(firefox71 fixed)
Tracking | Status | |
---|---|---|
firefox71 | --- | fixed |
People
(Reporter: descent-tact0m, Assigned: bhackett1024)
References
(Blocks 1 open bug)
Details
(Whiteboard: [debugger-mvp])
Attachments
(2 files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3887.7 Safari/537.36
Steps to reproduce:
Run debugger
in content script
Actual results:
Nothing happened
Expected results:
debugger paused at the line.
Comment 1•6 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
Comment 2•5 years ago
|
||
Hi, do you have a small test case?
Reporter | ||
Comment 3•5 years ago
|
||
Yes.
manifest.json
{
"$schema": "http://json.schemastore.org/chrome-manifest",
"name": "Debugger test",
"version": "1.5.3",
"manifest_version": 2,
"permissions": ["http://example.com/*", "webNavigation"],
"background": {
"scripts": ["/background.js"]
}
}
browser.webNavigation.onCommitted.addListener(
async arg => {
try {
await browser.tabs.executeScript(arg.tabId, {
runAt: 'document_start',
frameId: arg.frameId,
code: `alert('hello')
debugger
a(1, 2)
function a(x, y) {
return x + y
}
`
})
} catch (e) {}
},
{ url: [{ urlEquals: 'http://example.com/' }] }
)
Then open example.com, debugger paused at ExtensionContent.jsm:559
(Line 559: this.matcher.jsCode,)
instead of my debugger statement
Comment 4•5 years ago
|
||
Thanks for sharing. could you create a glitch example, which will make it easier to test?
I've never used a manifest.json, so this will be good for me to learn :)
Reporter | ||
Comment 5•5 years ago
|
||
Just put them in the same folder, open about:debugging#/runtime/this-firefox
, load "temporarily load add-on" then select the manifest.json.
Then open example.com
Comment 6•5 years ago
|
||
Thanks for the report!
I can reproduce the issue on my machine Win 10 with Firefox Nightly
Honza
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 7•5 years ago
|
||
The debugger is actually pausing at the debugger statement, but it isn't showing the correct source for the eval'ed script in which it has paused. When ExtensionContent.jsm calls Cu.evalInSandbox it doesn't provide a filename/lineno for the eval'ed script, so the calling script's location is used by default. When the debugger tries to get the source for that eval'ed script later on, it doesn't treat the source as javascript so it disregards the source's text and fetches it by URL, ending up with the source of ExtensionContent.jsm.
A simple fix here is to supply a special URL in the Cu.evalInSandbox call, which we can later pattern match on and identify as JS. The pattern matching is dissatisfying but there is lots of similar logic in TabSources.createSourceActor.
A better fix would be to overhaul our handling of source text so that we ensure we never show incorrect source contents in the debugger. I just filed bug 1582266 for that but I think we should do the simple fix first because the Cu.evalInSandbox call should change anyways so that we have a reasonable line number in the new source.
Assignee | ||
Comment 8•5 years ago
|
||
Updated•5 years ago
|
Comment 10•5 years ago
|
||
bugherder |
Description
•