5
votes

I created an example browser extension written in .html and typescript that is working fine in Chrome, Firefox and Edge (canary). Typescript compiler generated .js and .js.map files from the .ts files.

I want to debug the source code where I can place breakpoints to the typescript code. I can do it in Firefox, but not in Chrome or Edge. Chrome and Edge notice that the .map and .ts files are to be added, I can can load them only from the sources and breakpoints don't work for me.

I read past articles.

I tried different settings in manifest.json.

I can attach the whole zip with example extension, if I find a way. The whole list of files in extension is: background.html, background.js, background.js.map, background.ts, base.js, base.js.map, base.ts, content.js, content.js.map, content.ts, manifest.json, popup.html, popup.js, popup.js.map, popup.ts, readme.md, tsconfig.json, tsext16.PNG, tsext19.PNG,

The complete manifest.json is

{
    "manifest_version": 2,

    "name": "Typescript Sourcemaps in Browser Extensions",
    "version": "1",
    "description": "Sourcemaps with Extensions",

    "icons": {
        "16": "tsext16.png"
    },
    "permissions": [
        "activeTab"
    ],
    "browser_action": {
        "default_icon": {
            "16": "tsext16.png",
            "19": "tsext19.png"
        },
        "default_popup": "popup.html",
        "default_title": "Typescript example popup"
    },
    "background": {
        "scripts": [
            "base.js",
            "background.js"
        ]
    },
    "content_scripts": [{
        "matches": ["http://*/*", "https://*/*"],
        "js": [
            "base.js",
            "content.js"
            ]
    }],
    "web_accessible_resources": [
        "background.js.map",
        "background.ts",
        "*"
    ]
}

When looking at the Source pane, only .js files are shown. A the top of the .js file, there is a message "Source map detected". However, I don't know how to load .ts file (e.g. popup.ts) in a way that I can make breakpoints working. I can mark the breakpoints in any .ts file if I load it from "filesystem", but the execution doesn't stop and the file name as shown in the tab has an additional icon (what probably means "just for viewing, not connected to the debugger") similar to "new document".

I can debug this example extension in current Firefox 67. I can get source maps for web pages into Chrome. I tried at Windows 10 and Windows 7, both x64.

2
Let's add a bounty to thisavalanche1

2 Answers

0
votes

This is probably a chrome bug, which I reported a year ago and is still open.

To verify, please install chrome <=71 and try debugging. You're more than welcome to engage with chrome devs on the bug page.

0
votes

For Chrome extension, mapped files are allocated under "Content scripts" tab within "Sources" tab under Developer Tools. Not under default "Page" tab.

There is a source code of all enabled extensions, plus webpack:// files (if source maps are created with Webpack).

It's also possible to find mapped files using Cmd + P.

Chrome extension source maps