本文整理汇总了TypeScript中chrome-remote-interface.New函数的典型用法代码示例。如果您正苦于以下问题:TypeScript New函数的具体用法?TypeScript New怎么用?TypeScript New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: create
export async function create(html: string, options?: CreateOptions): Promise<CreateResult> {
const myOptions = Object.assign({}, options);
let chrome: LaunchedChrome;
myOptions._canceled = false;
if (myOptions.timeout >= 0) {
setTimeout(() => {
myOptions._canceled = true;
}, myOptions.timeout);
}
await throwIfCanceled(myOptions);
if (!myOptions.host && !myOptions.port) {
await throwIfCanceled(myOptions);
chrome = await launchChrome(myOptions);
}
try {
const tab = await CDP.New(myOptions);
try {
return await generate(html, myOptions, tab);
} finally {
await CDP.Close({ ...myOptions, id: tab.id });
}
} finally {
if (chrome) {
await chrome.kill();
}
}
}
示例2: connectToChrome
private async connectToChrome(): Promise<Client> {
const target = await CDP.New({
port: this.options.cdp.port,
host: this.options.cdp.host,
})
return await CDP({ target })
}
示例3: startChrome
private async startChrome(): Promise<Client> {
const { port } = this.options.cdp
this.chromeInstance = await launch({
logLevel: this.options.debug ? 'info' : 'silent',
chromeFlags: [
// Do not render scroll bars
'--hide-scrollbars',
// The following options copied verbatim from https://github.com/GoogleChrome/chrome-launcher/blob/master/src/flags.ts
// Disable built-in Google Translate service
'--disable-translate',
// Disable all chrome extensions entirely
'--disable-extensions',
// Disable various background network services, including extension updating,
// safe browsing service, upgrade detector, translate, UMA
'--disable-background-networking',
// Disable fetching safebrowsing lists, likely redundant due to disable-background-networking
'--safebrowsing-disable-auto-update',
// Disable syncing to a Google account
'--disable-sync',
// Disable reporting to UMA, but allows for collection
'--metrics-recording-only',
// Mute any audio
'--mute-audio',
// Skip first run wizards
'--no-first-run',
],
port,
})
const target = await CDP.New({
port,
})
return await CDP({ target, port })
}
示例4: initRuntimeClient
private async initRuntimeClient(): Promise<RuntimeClient> {
const target = await CDP.New()
const client = await CDP({ target })
await this.setViewport(client)
const runtime = new LocalRuntime(client, this.options)
return { client, runtime }
}
示例5: startChrome
private async startChrome(): Promise<Client> {
this.chromeInstance = await launch({
logLevel: this.options.debug ? 'info' : 'silent',
port: this.options.cdp.port,
})
const target = await CDP.New({
port: this.chromeInstance.port,
})
return await CDP({ target })
}