mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: addInitScript and auth (unsuccessful) in bidi (#32500)
This commit is contained in:
parent
728083b435
commit
d030965688
@ -195,8 +195,12 @@ export class BidiBrowserContext extends BrowserContext {
|
||||
this._authenticateProxyViaHeader();
|
||||
}
|
||||
|
||||
private _bidiPages() {
|
||||
return [...this._browser._bidiPages.values()].filter(bidiPage => bidiPage._browserContext === this);
|
||||
}
|
||||
|
||||
pages(): Page[] {
|
||||
return [];
|
||||
return this._bidiPages().map(bidiPage => bidiPage._initializedPage).filter(Boolean) as Page[];
|
||||
}
|
||||
|
||||
async newPageDelegate(): Promise<PageDelegate> {
|
||||
@ -269,11 +273,13 @@ export class BidiBrowserContext extends BrowserContext {
|
||||
}
|
||||
|
||||
async doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise<void> {
|
||||
this._options.httpCredentials = httpCredentials;
|
||||
for (const page of this.pages())
|
||||
await (page._delegate as BidiPage).updateHttpCredentials();
|
||||
}
|
||||
|
||||
async doAddInitScript(initScript: InitScript) {
|
||||
// for (const page of this.pages())
|
||||
// await (page._delegate as WKPage)._updateBootstrapScript();
|
||||
await Promise.all(this.pages().map(page => (page._delegate as BidiPage).addInitScript(initScript)));
|
||||
}
|
||||
|
||||
async doRemoveNonInternalInitScripts() {
|
||||
|
||||
@ -47,6 +47,7 @@ export class BidiPage implements PageDelegate {
|
||||
readonly _browserContext: BidiBrowserContext;
|
||||
readonly _networkManager: BidiNetworkManager;
|
||||
_initializedPage: Page | null = null;
|
||||
private _initScriptIds: string[] = [];
|
||||
|
||||
constructor(browserContext: BidiBrowserContext, bidiSession: BidiSession, opener: BidiPage | null) {
|
||||
this._session = bidiSession;
|
||||
@ -92,9 +93,14 @@ export class BidiPage implements PageDelegate {
|
||||
this.updateHttpCredentials(),
|
||||
this.updateRequestInterception(),
|
||||
this._updateViewport(),
|
||||
this._addAllInitScripts(),
|
||||
]);
|
||||
}
|
||||
|
||||
private async _addAllInitScripts() {
|
||||
return Promise.all(this._page.allInitScripts().map(initScript => this.addInitScript(initScript)));
|
||||
}
|
||||
|
||||
potentiallyUninitializedPage(): Page {
|
||||
return this._page;
|
||||
}
|
||||
@ -318,15 +324,20 @@ export class BidiPage implements PageDelegate {
|
||||
}
|
||||
|
||||
async addInitScript(initScript: InitScript): Promise<void> {
|
||||
await this._updateBootstrapScript();
|
||||
const { script } = await this._session.send('script.addPreloadScript', {
|
||||
// TODO: remove function call from the source.
|
||||
functionDeclaration: `() => { return ${initScript.source} }`,
|
||||
// TODO: push to iframes?
|
||||
contexts: [this._session.sessionId],
|
||||
});
|
||||
if (!initScript.internal)
|
||||
this._initScriptIds.push(script);
|
||||
}
|
||||
|
||||
async removeNonInternalInitScripts() {
|
||||
await this._updateBootstrapScript();
|
||||
}
|
||||
|
||||
async _updateBootstrapScript(): Promise<void> {
|
||||
throw new Error('Method not implemented.');
|
||||
const promises = this._initScriptIds.map(script => this._session.send('script.removePreloadScript', { script }));
|
||||
this._initScriptIds = [];
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
async closePage(runBeforeUnload: boolean): Promise<void> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user