puppeteer: Page with CSP breaks puppeteer
A page with CSP will break some of puppeteer methods, such as page.addScriptTag
. At the very least, we should fail gracefully.
It would be ideal to have a way to disable CSP altogether.
Reported in: #1091
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 80
- Comments: 32 (4 by maintainers)
Commits related to this issue
- fix(Page) Prevent silently failing when addScriptTag and addStyleTag violate Content Security Policy (#1229) — committed to yujiosaka/puppeteer by deleted user 7 years ago
- fix(Page): Fail on Content Security Policy by detecting Log.entryAdded (#1229) — committed to yujiosaka/puppeteer by deleted user 7 years ago
- fix(Page): teach Page.waitFor* function to work with strict CSP This patch removes function creation from WaitTask, making the following methods work with strict CSP policy: - frame.waitForFunction -... — committed to aslushnikov/puppeteer by aslushnikov 6 years ago
- test: add test for page.waitForFunction with script CSP This patch adds a test to fixate page.waitForFunction behavior for pages with CSP. References #1229. — committed to aslushnikov/puppeteer by aslushnikov 6 years ago
- test: add test for page.waitForFunction with script CSP (#2305) This patch adds a test to fixate page.waitForFunction behavior for pages with CSP. References #1229. — committed to puppeteer/puppeteer by aslushnikov 6 years ago
- feat(Chromium): roll Chromium to r548153 This roll includes: - https://crrev.com/547982 - v8 roll that includes [fixed Runtime.callFunctionOn](https://chromium.googlesource.com/v8/v8/+/1637818671c6... — committed to aslushnikov/puppeteer by aslushnikov 6 years ago
- feat(Chromium): roll Chromium to r548153 (#2312) This roll includes: - https://crrev.com/547982 - v8 roll that includes [fixed Runtime.callFunctionOn](https://chromium.googlesource.com/v8/v8/+/16... — committed to puppeteer/puppeteer by aslushnikov 6 years ago
- test: add test on Page.evaluateOnNewDocument with CSP This patch adds a test that Page.evaluateOnNewDocument works with CSP: there's been some concerns on the bugtracker before. References #1229 — committed to aslushnikov/puppeteer by aslushnikov 6 years ago
- test: add test on Page.evaluateOnNewDocument with CSP (#2319) This patch adds a test that Page.evaluateOnNewDocument works with CSP: there's been some concerns on the bugtracker before. Reference... — committed to puppeteer/puppeteer by aslushnikov 6 years ago
- DevTools: Page.addScriptTagshould throw when blocked by CSP This patch teaches Page.addScriptTag and Page.addStyleTag to throw an error when blocked by CSP. References #1229. — committed to aslushnikov/puppeteer by aslushnikov 6 years ago
- feat(Page): Page.addScriptTag should throw when blocked by CSP (#2320) This patch teaches Page.addScriptTag and Page.addStyleTag to throw an error when blocked by CSP. References #1229. — committed to puppeteer/puppeteer by aslushnikov 6 years ago
- feat(Chromium): roll Chromium to r548690 This roll includes: - https://crrev.com/548598 - DevTools: implement Page.setBypassCSP method - https://crrev.com/548690 - DevTools: introduce Page.navigatedW... — committed to aslushnikov/puppeteer by aslushnikov 6 years ago
- feat(Chromium): roll Chromium to r548690 (#2323) This roll includes: - https://crrev.com/548598 - DevTools: implement Page.setBypassCSP method - https://crrev.com/548690 - DevTools: introduce Page.... — committed to puppeteer/puppeteer by aslushnikov 6 years ago
+1 for ability to disable CSP.
Use case: I’m using puppeteer as a post-build crawler to generate a static dump of my SPA. When crawling, I’d like to inline critical CSS, and add a CSP directive for the CSS text hash. While I’m at it, I want to change the API server from
localhost:port
toapi.example.com
. However, if my page already had a CSP meta tag in it (which is good to have during development so I can catch CSP violations early), puppeteer starts getting funky. Would love it if I can disable CSP altogether when crawling.Here’s my workaround:
Related: #599
+1 for ability to disable CSP.
Thank you.
+1 for fixing this.
Upgrade to v1.0.0, fails all my tests too, due to the same reason (all WaitFor… methods failing due to CSP) Rolling back to v0.13.0.
Thanks @niieani — your solution inspired this simplified approach for a backstopjs usecase https://github.com/garris/BackstopJS/commit/67801c259f340c986bd0c25281a7eb5a79c7bc25
@aslushnikov looking forward to #2324! 🎁
Great to hear it was useful @garris! Also looking forward to #2324 😃
Thanks @aslushnikov! I’ve got tests that were passing with an interception workaround (thanks @niieani for the idea)… removed the interception, installed from your fork and the tests still pass. 😃
Just downgrade to version
0.13
, it works great. Waiting for update hereThanks @andrewlinfoot ! I use typescript too, so it’s perfect!
When trying to inject a Javascript file, there’s no need to downgrade here. Simply replicate the 0.13.0 previous code, such as:
Was never CSP in the headers at all… was meta tags with CSP who was the culprit.