Closed Bug 1577407 Opened 5 months ago Closed 4 months ago

debugger statement not working in content script

Categories

(DevTools :: Debugger, defect, P2)

70 Branch
defect

Tracking

(firefox71 fixed)

RESOLVED FIXED
Firefox 71
Tracking Status
firefox71 --- fixed

People

(Reporter: jackworks, Assigned: bhackett1024)

References

(Blocks 2 open bugs)

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.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Debugger
Product: Firefox → DevTools

Hi, do you have a small test case?

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

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 :)

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

Attached image image.png

Thanks for the report!

I can reproduce the issue on my machine Win 10 with Firefox Nightly

Honza

Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P2
Assignee: nobody → bhackett1024
Whiteboard: [debugger-mvp]

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.

Pushed by bhackett@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/a2f7185ec909
Mark extension evaluated code appropriately for the debugger, r=jlast.
Status: NEW → ASSIGNED
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 71
You need to log in before you can comment on or make changes to this bug.