Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await Page.stopScreencast()
log('We think the page has finished doing what it do. Rendering video.')
log(`Interaction took ${Date.now() - interactionStartTime}ms to finish.`)
} catch (error) {
console.error(error)
}
// @TODO: handle this better —
// If you don't close the tab, an a subsequent Page.navigate() is unable to load the url,
// you'll end up printing a PDF of whatever was loaded in the tab previously
// (e.g. a previous URL) _unless_ you Cdp.New() each time. But still good to close to
// clear up memory in Chrome
try {
log('trying to close tab', tab)
await Cdp.Close({ id: tab.id })
} catch (error) {
log('unable to close tab', tab, error)
}
await client.close()
const renderVideo = async () => {
await new Promise((resolve, reject) => {
const args = [
'-y',
'-loglevel',
'warning', // 'debug',
'-f',
'image2',
'-framerate',
`${options.videoFrameRate}`,
public async close() {
debug(`Pending tabs: ${this._tabs.length}`);
while (this._tabs.length > 0) {
const tab = this._tabs.pop();
try {
await cdp.Close({ id: tab.id, port: (this._client as any).port }); // eslint-disable-line new-cap
} catch (e) {
debug(`Couldn't close tab ${tab.id}`);
}
}
try {
(this._client as any).close();
/*
* We need to wait until the browser is closed because
* in tests if we close the client and at the same time
* the next test tries to open a new tab, an error is
* thrown.
*/
await this.isClosed();
async closeTab(tabId) {
try {
// https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-closeTarget
await chrome.Close({
port: this.port,
id: tabId,
});
delete this.tabs[tabId];
} catch (err) {
throw err;
}
}
.on('end', () => {
CDP.Close(target)
.then(() => process.exit(0))
.catch(fatal);
});
})
static Close (...args) {
return CDP.Close(...args)
}
function closeTab(tabId, options) {
return CDP.Close({
id : tabId,
port: options && options.port || Tab.settings.port
});
}
static Close (...args) {
return CDP.Close(...args)
}
}).then((screenshot) => {
const buffer = new Buffer(screenshot.data, 'base64');
client.close();
CDP.Close({id: client.target.id, host: cdpHost, port: cdpPort})
.then(() => resolve(buffer))
.catch(e => reject(e));
}).catch((e) => reject(e));
}, delay);