mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: reuse SetContent across implementations (#9894)
This commit is contained in:
parent
8bd73175e0
commit
c6a9404bb4
@ -38,7 +38,12 @@ import {
|
||||
InnerLazyParams,
|
||||
NodeFor,
|
||||
} from './types.js';
|
||||
import {addPageBinding, createJSHandle, debugError} from './util.js';
|
||||
import {
|
||||
addPageBinding,
|
||||
createJSHandle,
|
||||
debugError,
|
||||
setPageContent,
|
||||
} from './util.js';
|
||||
import {TaskManager, WaitTask} from './WaitTask.js';
|
||||
|
||||
/**
|
||||
@ -276,13 +281,9 @@ export class IsolatedWorld {
|
||||
waitUntil = ['load'],
|
||||
timeout = this.#timeoutSettings.navigationTimeout(),
|
||||
} = 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 => {
|
||||
document.open();
|
||||
document.write(html);
|
||||
document.close();
|
||||
}, html);
|
||||
|
||||
await setPageContent(this, html);
|
||||
|
||||
const watcher = new LifecycleWatcher(
|
||||
this.#frameManager,
|
||||
this.#frame,
|
||||
|
@ -25,7 +25,7 @@ import {EventEmitter} from '../EventEmitter.js';
|
||||
import {PuppeteerLifeCycleEvent} from '../LifecycleWatcher.js';
|
||||
import {TimeoutSettings} from '../TimeoutSettings.js';
|
||||
import {EvaluateFunc, HandleFor} from '../types.js';
|
||||
import {isString, waitWithTimeout} from '../util.js';
|
||||
import {isString, setPageContent, waitWithTimeout} from '../util.js';
|
||||
|
||||
import {Connection} from './Connection.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
@ -210,13 +210,7 @@ export class Context extends EventEmitter {
|
||||
) as string;
|
||||
|
||||
await Promise.all([
|
||||
// We rely upon the fact that document.open() will reset frame lifecycle with "init"
|
||||
// lifecycle event. @see https://crrev.com/608658
|
||||
this.evaluate(html => {
|
||||
document.open();
|
||||
document.write(html);
|
||||
document.close();
|
||||
}, html),
|
||||
setPageContent(this, html),
|
||||
waitWithTimeout(
|
||||
new Promise<void>(resolve => {
|
||||
this.once(waitUntilCommand, () => {
|
||||
|
@ -20,6 +20,7 @@ import type {Protocol} from 'devtools-protocol';
|
||||
|
||||
import type {ElementHandle} from '../api/ElementHandle.js';
|
||||
import type {JSHandle} from '../api/JSHandle.js';
|
||||
import {Page} from '../api/Page.js';
|
||||
import {isNode} from '../environment.js';
|
||||
import {assert} from '../util/assert.js';
|
||||
import {isErrorLike} from '../util/ErrorLike.js';
|
||||
@ -441,3 +442,19 @@ export async function getReadableFromProtocolStream(
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export async function setPageContent(
|
||||
page: Pick<Page, 'evaluate'>,
|
||||
content: string
|
||||
): Promise<void> {
|
||||
// We rely upon the fact that document.open() will reset frame lifecycle with "init"
|
||||
// lifecycle event. @see https://crrev.com/608658
|
||||
return page.evaluate(html => {
|
||||
document.open();
|
||||
document.write(html);
|
||||
document.close();
|
||||
}, content);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user