tulios / json-viewer

It is a Chrome extension for printing JSON and JSONP.
https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh
MIT License
3.31k stars 678 forks source link

Doesn't work on JSON endpoints with sandbox CSP #178

Closed ngyikp closed 6 years ago

ngyikp commented 6 years ago

Reproduction URLs:

Both of these URLs have a response header of Content-Security-Policy: sandbox

Tested on user-agents:

Expected result: The JSON viewer should work.

Actual result: Doesn't work at all, page is completely blank, and a console error appears: Blocked script execution in 'https://untitled-8bobienkqieg.runkit.sh/' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

It's a misleading error, the extension's content script does run but halts at one point. I did some investigation and it might be a Chrome bug, setTimeout and setInterval doesn't work in the sandbox CSP, but requestAnimationFrame or requestIdleCallback works.

I tried this patch and it works, there's still some buggy behaviour but at least it's not a white screen anymore.

Another thing with requestAnimationFrame is that only Chrome 24+ has the unprefixed version and the manifest's minimum Chrome version is 21, but I think no one should be using an ancient Chrome anymore :) (replaced with https://github.com/tulios/json-viewer/issues/210)

psyrendust commented 6 years ago

I'm getting the same issue.

VladimirAlexiev commented 6 years ago

https://github.com/tulios/json-viewer/pull/209. If @tulios doesn't merge it soon, I'm switching too.

ngyikp commented 6 years ago

The Chrome bug has been reported by someone else, and fixed in Chrome 68 :) https://bugs.chromium.org/p/chromium/issues/detail?id=811528