Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass CSP for img.src in Chromium #33

Open
deevroman opened this issue Aug 24, 2024 · 1 comment
Open

Bypass CSP for img.src in Chromium #33

deevroman opened this issue Aug 24, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@deevroman
Copy link
Owner

Currently, switching satellite images only works in Firefox. It is implemented by simply replacing the src tag

i.src = SatellitePrefix + xyz.z + "/" + xyz.y + "/" + xyz.x;

But this does not work in Chromium, which for some reason takes into account image-src CSP

  1. Possible workaround

Create an with the desired tile using GM_AddElement, and call replaceWith()

const newImg = GM_addElement(document.body, "img", {
src: SatellitePrefix + xyz.z + "/" + xyz.y + "/" + xyz.x
})
newImg.classList = i.classList
newImg.style.cssText = i.style.cssText;
i.replaceWith(newImg)

But this breaks Leaflet: when zooming in, new tiles are not loaded (you can get around it by switching tiles twice)

replaceWith probably breaks tile object references that are important for Leaflet. (event handlers?)


I have no idea how to overcome this or even understanding how GM_addElement bypasses CSP

Interesting points in the ViolentMonkey source code

https://github.com/violentmonkey/violentmonkey/blob/692ffb97743fbbcd549d1ed81969e915125ebfd7/src/injected/content/gm-api-content.js#L31

https://github.com/violentmonkey/violentmonkey/blob/692ffb97743fbbcd549d1ed81969e915125ebfd7/src/background/utils/preinject.js#L625

@deevroman deevroman added the help wanted Extra attention is needed label Aug 24, 2024
@deevroman
Copy link
Owner Author

Not exactly about CSP, but probably solving this problem will also help to bypass bypass CORS for some imagery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant