html2canvas causing CSP errors in manifest version 3

302 views
Skip to first unread message

D T

unread,
Oct 6, 2022, 12:49:02 AM10/6/22
to Chromium Extensions
Hi fellow developers,

I am developing an extension that needs to take a screenshot image of a section of the screen and download it to the users download folder.

Originally I experimented with Chromes' native chrome API "captureVisibleTab" method however it only captures the the visible area of the screen.  In my situation the content I need to capture could be slightly off screen and need to be scrolled to.  Scrolling and patching multiple calls to captureVisibleTab is not an exact science and difficult to achieve not to mention not optimal performance.

I know that html2canvas FAQ does say to use native Chrome API to take screenshots and not to use their library for these purposes. The fact is however it works, and the CSP errors I get are errors in the console but not critical and execution continues uninterrupted.

Here is the error message from the console:

"html2canvas.min.v1.4.1.js:20 Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'"...."

Failure line of code: o.replaceChild(o.adoptNode(this.documentElement), o.documentElement),

So my questions come down to the following:

1) What are my best options programmatically to get a screen capture of a section of the screen even when the page is not contained within the visible portion of the tab?

2) My extension works in dev tools despite it throwing CSP errors.  Can I publish my MV3 extension to the chrome store even with the CSP error above?

3) As a test I ran my extension on a different site and the CSP did not surface when the html2canvas library was called.  Both sites are https sites (if that matters).  There is no cross domain stuff going on here and the html2canvas library (all my js files are local).  I am stumped why the exact same code runs differently on two different sites. Any ideas how to get the CSP errors to stop whilst still using the html2canvas library would be helpful. If anyone knows please reply?   

Thanks,
DT
Reply all
Reply to author
Forward
0 new messages