PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.03k stars 346 forks source link

[BUG] Sourcemaps off by 1 line #856

Open bot101 opened 8 months ago

bot101 commented 8 months ago

What happened?

While debugging extensions in Chrome Devtools, the sourcemaps in content scripts are off by one line. I have this experience working on 2 different extensions. In the screenshot, the breakpoint on line 55 actually activates for line 54, and the debug cursor is currently acting on line 55. Is there a fix for this issue?

image

Version

Latest

What OS are you seeing the problem on?

Windows

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

(OPTIONAL) Contribution

Code of Conduct

lionelhorn commented 7 months ago

I made a simple test case using example "with-content-scripts-ui"

image

Green arrows shows the same comment in code. But the mapping from generated file to original source is wrong. Line 7 in code is mapped to something else. As indicated with the red arrow.

Using https://sokra.github.io/source-map-visualization/#custom as a viewer.

Test file used.

// 

console.log("line 3")

// Comment on line 7

function a() {
    return "line 10"
}

console.log("line 13" +
    " & 14")

export const z = {line: "17 EOF"}
lionelhorn commented 7 months ago

Using this tool https://evanw.github.io/source-map-visualization/ issue is even clearer.

image
Nintynuts commented 5 months ago

I've also run into this issue, verified it with the visualization tool, and it's making debugging impossible. I searched for this issue on the web generally, and it seems like something that other people have encountered years ago, but it's unclear whether a fix was found as the issues usually go stale. I presume that plasmo gets this functionality from somewhere else (maybe webpack, but I'm not sure if webpack then gets it from somewhere else), so I guess it needs fixing there and then plasmo would need to update its dependencies?

I really hope this can be fixed soon, because it's my only issue with Plamo. Everything else has been great.