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