Skip to content

Commit

Permalink
feat(firefox): support Page.setJavascriptEnabled (#3970)
Browse files Browse the repository at this point in the history
This patch implements:
- Page.setJavascriptEnabled
- Page.setCacheEnabled
  • Loading branch information
aslushnikov committed Feb 9, 2019
1 parent edb6f62 commit b82cc15
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
14 changes: 14 additions & 0 deletions experimental/puppeteer-firefox/lib/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ class Page extends EventEmitter {
await this._session.send('Page.setUserAgent', {userAgent});
}

/**
* @param {string} userAgent
*/
async setJavaScriptEnabled(enabled) {
await this._session.send('Page.setJavascriptEnabled', {enabled});
}

/**
* @param {string} userAgent
*/
async setCacheEnabled(enabled) {
await this._session.send('Page.setCacheDisabled', {cacheDisabled: !enabled});
}

/**
* @param {{viewport: !Puppeteer.Viewport, userAgent: string}} options
*/
Expand Down
2 changes: 1 addition & 1 deletion experimental/puppeteer-firefox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"node": ">=8.9.4"
},
"puppeteer": {
"firefox_revision": "ba500612786aac157fa44e6b4d04c852f51ea35c"
"firefox_revision": "592ca01fa3d2566a9f494e2df8ca6876c5b5b4bb"
},
"scripts": {
"install": "node install.js",
Expand Down
22 changes: 13 additions & 9 deletions test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device
});
});

describe_fails_ffox('Page.setJavaScriptEnabled', function() {
describe('Page.setJavaScriptEnabled', function() {
it('should work', async({page, server}) => {
await page.setJavaScriptEnabled(false);
await page.goto('data:text/html, <script>var something = "forbidden"</script>');
Expand All @@ -922,18 +922,22 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device
});
});

describe_fails_ffox('Page.setCacheEnabled', function() {
describe('Page.setCacheEnabled', function() {
it('should enable or disable the cache based on the state passed', async({page, server}) => {
const responses = new Map();
page.on('response', r => responses.set(r.url().split('/').pop(), r));

await page.goto(server.PREFIX + '/cached/one-style.html');
await page.reload();
expect(responses.get('one-style.css').fromCache()).toBe(true);
const [cachedRequest] = await Promise.all([
server.waitForRequest('/cached/one-style.html'),
page.reload(),
]);
// Rely on "if-modified-since" caching in our test server.
expect(cachedRequest.headers['if-modified-since']).not.toBe(undefined);

await page.setCacheEnabled(false);
await page.reload({waitUntil: 'networkidle2'});
expect(responses.get('one-style.css').fromCache()).toBe(false);
const [nonCachedRequest] = await Promise.all([
server.waitForRequest('/cached/one-style.html'),
page.reload(),
]);
expect(nonCachedRequest.headers['if-modified-since']).toBe(undefined);
});
});

Expand Down

0 comments on commit b82cc15

Please sign in to comment.