mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor: move setContent to common impl (#11455)
Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
This commit is contained in:
parent
1014abc087
commit
8be3e797bb
@ -804,6 +804,17 @@ export abstract class Frame extends EventEmitter<FrameEvents> {
|
||||
}
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async setFrameContent(content: string): Promise<void> {
|
||||
return await this.evaluate(html => {
|
||||
document.open();
|
||||
document.write(html);
|
||||
document.close();
|
||||
}, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* The frame's `name` attribute as specified in the tag.
|
||||
*
|
||||
|
@ -39,7 +39,7 @@ import type {WaitForSelectorOptions} from '../api/Page.js';
|
||||
import {UnsupportedOperation} from '../common/Errors.js';
|
||||
import type {TimeoutSettings} from '../common/TimeoutSettings.js';
|
||||
import type {Awaitable, NodeFor} from '../common/types.js';
|
||||
import {UTILITY_WORLD_NAME, setPageContent, timeout} from '../common/util.js';
|
||||
import {UTILITY_WORLD_NAME, timeout} from '../common/util.js';
|
||||
import {Deferred} from '../util/Deferred.js';
|
||||
import {disposeSymbol} from '../util/disposable.js';
|
||||
|
||||
@ -174,7 +174,7 @@ export class BidiFrame extends Frame {
|
||||
._waitWithNetworkIdle(
|
||||
forkJoin([
|
||||
fromEvent(this.#context, waitEvent).pipe(first()),
|
||||
from(setPageContent(this, html)),
|
||||
from(this.setFrameContent(html)),
|
||||
]).pipe(
|
||||
map(() => {
|
||||
return null;
|
||||
|
@ -21,7 +21,6 @@ import {Frame, FrameEvent, throwIfDetached} from '../api/Frame.js';
|
||||
import type {HTTPResponse} from '../api/HTTPResponse.js';
|
||||
import type {WaitTimeoutOptions} from '../api/Page.js';
|
||||
import {UnsupportedOperation} from '../common/Errors.js';
|
||||
import {setPageContent} from '../common/util.js';
|
||||
import {Deferred} from '../util/Deferred.js';
|
||||
import {disposeSymbol} from '../util/disposable.js';
|
||||
import {isErrorLike} from '../util/ErrorLike.js';
|
||||
@ -262,7 +261,9 @@ export class CdpFrame extends Frame {
|
||||
timeout = this._frameManager.timeoutSettings.navigationTimeout(),
|
||||
} = options;
|
||||
|
||||
await setPageContent(this.isolatedRealm(), html);
|
||||
// We rely upon the fact that document.open() will reset frame lifecycle with "init"
|
||||
// lifecycle event. @see https://crrev.com/608658
|
||||
await this.setFrameContent(html);
|
||||
|
||||
const watcher = new LifecycleWatcher(
|
||||
this._frameManager.networkManager,
|
||||
|
@ -31,7 +31,6 @@ import {
|
||||
raceWith,
|
||||
} from '../../third_party/rxjs/rxjs.js';
|
||||
import type {CDPSession} from '../api/CDPSession.js';
|
||||
import type {Page} from '../api/Page.js';
|
||||
import {isNode} from '../environment.js';
|
||||
import {assert} from '../util/assert.js';
|
||||
import type {Deferred} from '../util/Deferred.js';
|
||||
@ -504,22 +503,6 @@ 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 await page.evaluate(html => {
|
||||
document.open();
|
||||
document.write(html);
|
||||
document.close();
|
||||
}, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user