fix(page): teach page.setContent to work with tricky content (#4366)

Fix #4364
This commit is contained in:
Andrey Lushnikov 2019-04-30 00:35:05 -07:00 committed by GitHub
parent e2e6b88934
commit 27c9f754b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -132,11 +132,11 @@ class DOMWorld {
* @param {string} html
*/
async setContent(html) {
await this.evaluate(html => {
await this.evaluate(base64html => {
document.open();
document.write(html);
document.write(atob(base64html));
document.close();
}, html);
}, Buffer.from(html).toString('base64'));
}
/**

View File

@ -203,11 +203,11 @@ class DOMWorld {
} = options;
// We rely upon the fact that document.open() will reset frame lifecycle with "init"
// lifecycle event. @see https://crrev.com/608658
await this.evaluate(html => {
await this.evaluate(base64html => {
document.open();
document.write(html);
document.write(atob(base64html));
document.close();
}, html);
}, Buffer.from(html).toString('base64'));
const watcher = new LifecycleWatcher(this._frameManager, this._frame, waitUntil, timeout);
const error = await Promise.race([
watcher.timeoutOrTerminationPromise(),

View File

@ -749,6 +749,10 @@ module.exports.addTests = function({testRunner, expect, headless, puppeteer, CHR
for (let i = 0; i < 20; ++i)
await page.setContent('<div>yo</div>');
});
it('should work with tricky content', async({page, server}) => {
await page.setContent('<div>hello world</div>' + '\x7F');
expect(await page.$eval('div', div => div.textContent)).toBe('hello world');
});
});
describe_fails_ffox('Page.setBypassCSP', function() {