Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #105 from celeryclub/handle-cdp-errors
Browse files Browse the repository at this point in the history
Handle some more CDP errors
  • Loading branch information
jperl authored Jul 23, 2020
2 parents 6d6998d + c3517fb commit f140c65
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/ScreencastFrameCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ export class ScreencastFrameCollector extends EventEmitter {
}

private _uninstallPopupFollower(page: Page): void {
// Fixed in https://github.com/microsoft/playwright/pull/2307
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
page.off('popup', this._popupFollower);
}

Expand Down Expand Up @@ -111,19 +108,38 @@ export class ScreencastFrameCollector extends EventEmitter {
private async _activatePage(page: Page): Promise<void> {
debug('activating page: ', page.url());

let client;

try {
client = await this._buildClient(page);
} catch (e) {
// capture error so it does not propagate to the user
// this is most likely due to the page not being open
// long enough to attach the CDP session
debug('error building client %j', e.message);
return;
}

const previousClient = this._getActiveClient();

if (previousClient) {
await previousClient.send('Page.stopScreencast');
}

const client = await this._buildClient(page);
this._clients.push(client);
this._listenForFrames(client);

await client.send('Page.startScreencast', {
everyNthFrame: 1,
});
try {
await client.send('Page.startScreencast', {
everyNthFrame: 1,
});
} catch (e) {
// capture error so it does not propagate to the user
// this is most likely due to the page not being open
// long enough to start recording after attaching the CDP session
this._deactivatePage(page);
debug('error activating page %j', e.message);
}
}

private async _deactivatePage(page: Page): Promise<void> {
Expand All @@ -139,7 +155,7 @@ export class ScreencastFrameCollector extends EventEmitter {
everyNthFrame: 1,
});
} catch (e) {
debug('error reactivating original page %j', e.message);
debug('error reactivating previous page %j', e.message);
}
}

Expand Down

0 comments on commit f140c65

Please sign in to comment.