diff --git a/experimental/puppeteer-firefox/lib/DOMWorld.js b/experimental/puppeteer-firefox/lib/DOMWorld.js index 096c06f2b8e..8d50da02370 100644 --- a/experimental/puppeteer-firefox/lib/DOMWorld.js +++ b/experimental/puppeteer-firefox/lib/DOMWorld.js @@ -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')); } /** diff --git a/lib/DOMWorld.js b/lib/DOMWorld.js index 1668fad0034..503df690a9c 100644 --- a/lib/DOMWorld.js +++ b/lib/DOMWorld.js @@ -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(), diff --git a/test/page.spec.js b/test/page.spec.js index 1560a416358..4b4290d3fce 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -749,6 +749,10 @@ module.exports.addTests = function({testRunner, expect, headless, puppeteer, CHR for (let i = 0; i < 20; ++i) await page.setContent('
yo
'); }); + it('should work with tricky content', async({page, server}) => { + await page.setContent('
hello world
' + '\x7F'); + expect(await page.$eval('div', div => div.textContent)).toBe('hello world'); + }); }); describe_fails_ffox('Page.setBypassCSP', function() {