support provisional page changes for setEmulatedMedia

This commit is contained in:
Yury Semikhatsky 2020-01-22 14:02:30 -08:00
parent 652789457f
commit 94461f9355

View file

@ -220,16 +220,18 @@ export class WKPage implements PageDelegate {
method: T, method: T,
params?: Protocol.CommandParameters[T] params?: Protocol.CommandParameters[T]
): Promise<void> { ): Promise<void> {
const promises = [ await this._forAllsSessions(session => session.send(method, params).then());
this._session.send(method, params) }
private async _forAllsSessions(callback: ((session: WKSession) => Promise<void>)): Promise<void> {
const sessions = [
this._session
]; ];
// If the state changes during provisional load, push it to the provisional page // If the state changes during provisional load, push it to the provisional page
// as well to always be in sync with the backend. // as well to always be in sync with the backend.
if (this._provisionalPage) if (this._provisionalPage)
promises.push(this._provisionalPage._session.send(method, params)); sessions.push(this._provisionalPage._session);
for (const p of promises) await Promise.all(sessions.map(session => callback(session).catch(debugError)));
p.catch(debugError);
await Promise.all(promises);
} }
private _onFrameStoppedLoading(frameId: string) { private _onFrameStoppedLoading(frameId: string) {
@ -373,7 +375,7 @@ export class WKPage implements PageDelegate {
} }
async setEmulateMedia(mediaType: types.MediaType | null, colorScheme: types.ColorScheme | null): Promise<void> { async setEmulateMedia(mediaType: types.MediaType | null, colorScheme: types.ColorScheme | null): Promise<void> {
await WKPage._setEmulateMedia(this._session, mediaType, colorScheme); await this._forAllsSessions(session => WKPage._setEmulateMedia(session, mediaType, colorScheme));
} }
async setViewport(viewport: types.Viewport): Promise<void> { async setViewport(viewport: types.Viewport): Promise<void> {