mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
parent
63e2b36d29
commit
a1414de42f
@ -56,6 +56,7 @@
|
||||
+ [page.screenshot([options])](#pagescreenshotoptions)
|
||||
+ [page.setContent(html)](#pagesetcontenthtml)
|
||||
+ [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders)
|
||||
+ [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled)
|
||||
+ [page.setRequestInterceptionEnabled(value)](#pagesetrequestinterceptionenabledvalue)
|
||||
+ [page.setUserAgent(userAgent)](#pagesetuseragentuseragent)
|
||||
+ [page.setViewport(viewport)](#pagesetviewportviewport)
|
||||
@ -659,6 +660,11 @@ The extra HTTP headers will be sent with every request the page initiates.
|
||||
|
||||
> **NOTE** page.setExtraHTTPHeaders does not guarantee the order of headers in the outgoing requests.
|
||||
|
||||
#### page.setJavaScriptEnabled(enabled)
|
||||
- `enabled` <[boolean]> Whether or not to enabled JavaScript on the page.
|
||||
- returns: <[Promise]>
|
||||
|
||||
> **NOTE** changing this value won't affect scripts that have already been run. It will take full effect on the next [navigation](#pagegotourl-options).
|
||||
|
||||
#### page.setRequestInterceptionEnabled(value)
|
||||
- `value` <[boolean]> Whether to enable request interception.
|
||||
|
@ -385,6 +385,13 @@ class Page extends EventEmitter {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} enabled
|
||||
*/
|
||||
async setJavaScriptEnabled(enabled) {
|
||||
await this._client.send('Emulation.setScriptExecutionDisabled', { value: !enabled });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?string} mediaType
|
||||
* @return {!Promise}
|
||||
|
18
test/test.js
18
test/test.js
@ -1696,6 +1696,24 @@ describe('Page', function() {
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Page.setJavaScriptEnabled', function() {
|
||||
it('should work', SX(async function() {
|
||||
await page.setJavaScriptEnabled(false);
|
||||
await page.goto('data:text/html, <script>var something = "forbidden"</script>');
|
||||
let error = null;
|
||||
try {
|
||||
await page.evaluate('something');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
expect(error.message).toContain('something is not defined');
|
||||
|
||||
await page.setJavaScriptEnabled(true);
|
||||
await page.goto('data:text/html, <script>var something = "forbidden"</script>');
|
||||
expect(await page.evaluate('something')).toBe('forbidden');
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Page.evaluateOnNewDocument', function() {
|
||||
it('should evaluate before anything else on the page', SX(async function() {
|
||||
await page.evaluateOnNewDocument(function(){
|
||||
|
Loading…
Reference in New Issue
Block a user