fix: async stacks should work now (#325)

This commit is contained in:
Dmitry Gozman 2019-12-20 15:31:20 -08:00 committed by Pavel Feldman
parent 56a48559c2
commit 92ef4c173e
6 changed files with 34 additions and 58 deletions

View File

@ -14,15 +14,4 @@
* limitations under the License.
*/
const {helper} = require('./lib/helper');
const api = require('./lib/api');
for (const className in api.Chromium) {
// Playwright-web excludes certain classes from bundle, e.g. BrowserFetcher.
if (typeof api.Chromium[className] === 'function')
helper.installAsyncStackHooks(api.Chromium[className]);
}
const { CRPlaywright } = require('./lib/chromium/crPlaywright');
const packageJson = require('./package.json');
module.exports = new CRPlaywright(__dirname, packageJson.playwright.chromium_revision);
module.exports = require('./index').playwright('chromium');

View File

@ -14,15 +14,4 @@
* limitations under the License.
*/
const {helper} = require('./lib/helper');
const api = require('./lib/api');
for (const className in api.Firefox) {
// Playwright-web excludes certain classes from bundle, e.g. BrowserFetcher.
if (typeof api.Firefox[className] === 'function')
helper.installAsyncStackHooks(api.Firefox[className]);
}
const { FFPlaywright } = require('./lib/firefox/ffPlaywright');
const packageJson = require('./package.json');
module.exports = new FFPlaywright(__dirname, packageJson.playwright.firefox_revision);
module.exports = require('./index').playwright('firefox');

View File

@ -1,12 +1,22 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {helper} = require('./lib/helper');
const api = require('./lib/api');
const packageJson = require('./package.json');
for (const className in api) {
// Playwright-web excludes certain classes from bundle, e.g. BrowserFetcher.
if (typeof api[className] === 'function')
helper.installAsyncStackHooks(api[className]);
}
module.exports.playwright = browser => {
if (browser === 'chromium')
return require('./chromium');
return new api.Chromium(__dirname, packageJson.playwright.chromium_revision);
if (browser === 'firefox')
return require('./firefox');
return new api.Firefox(__dirname, packageJson.playwright.firefox_revision);
if (browser === 'webkit')
return require('./webkit');
return new api.WebKit(__dirname, packageJson.playwright.webkit_revision);
throw new Error(`Unsupported browser "${browser}"`);
};

View File

@ -651,7 +651,7 @@ export class Frame {
await handle.dispose();
}
waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options: any = {}, ...args: any[]): Promise<js.JSHandle | null> {
async waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options: any = {}, ...args: any[]): Promise<js.JSHandle | null> {
if (helper.isString(selectorOrFunctionOrTimeout))
return this.waitForSelector(selectorOrFunctionOrTimeout as string, options) as any;
if (helper.isNumber(selectorOrFunctionOrTimeout))
@ -691,7 +691,7 @@ export class Frame {
return result.asElement() as dom.ElementHandle<Element>;
}
waitForFunction(pageFunction: Function | string, options?: types.WaitForFunctionOptions, ...args: any[]): Promise<js.JSHandle> {
async waitForFunction(pageFunction: Function | string, options?: types.WaitForFunctionOptions, ...args: any[]): Promise<js.JSHandle> {
options = { timeout: this._page._timeoutSettings.timeout(), ...(options || {}) };
const task = dom.waitForFunctionTask(undefined, pageFunction, options, ...args);
return this._scheduleRerunnableTask(task, 'main', options.timeout);

View File

@ -177,11 +177,11 @@ export class Page extends EventEmitter {
return this.mainFrame().evaluateHandle(pageFunction, ...args as any);
}
$eval: types.$Eval = (selector, pageFunction, ...args) => {
$eval: types.$Eval = async (selector, pageFunction, ...args) => {
return this.mainFrame().$eval(selector, pageFunction, ...args as any);
}
$$eval: types.$$Eval = (selector, pageFunction, ...args) => {
$$eval: types.$$Eval = async (selector, pageFunction, ...args) => {
return this.mainFrame().$$eval(selector, pageFunction, ...args as any);
}
@ -279,15 +279,15 @@ export class Page extends EventEmitter {
return this.mainFrame().url();
}
content(): Promise<string> {
async content(): Promise<string> {
return this.mainFrame().content();
}
setContent(html: string, options?: frames.NavigateOptions): Promise<void> {
async setContent(html: string, options?: frames.NavigateOptions): Promise<void> {
return this.mainFrame().setContent(html, options);
}
goto(url: string, options?: frames.GotoOptions): Promise<network.Response | null> {
async goto(url: string, options?: frames.GotoOptions): Promise<network.Response | null> {
return this.mainFrame().goto(url, options);
}
@ -346,7 +346,6 @@ export class Page extends EventEmitter {
return waitPromise;
}
async emulateMedia(options: { type?: input.MediaType, colorScheme?: input.ColorScheme }) {
assert(!options.type || input.mediaTypes.has(options.type), 'Unsupported media type: ' + options.type);
assert(!options.colorScheme || input.mediaColorSchemes.has(options.colorScheme), 'Unsupported color scheme: ' + options.colorScheme);
@ -372,7 +371,7 @@ export class Page extends EventEmitter {
return this._state.viewport;
}
evaluate: types.Evaluate = (pageFunction, ...args) => {
evaluate: types.Evaluate = async (pageFunction, ...args) => {
return this.mainFrame().evaluate(pageFunction, ...args as any);
}
@ -392,7 +391,7 @@ export class Page extends EventEmitter {
return this._screenshotter.screenshotPage(options);
}
title(): Promise<string> {
async title(): Promise<string> {
return this.mainFrame().title();
}
@ -410,39 +409,39 @@ export class Page extends EventEmitter {
return this._closed;
}
click(selector: string, options?: frames.WaitForOptions & input.ClickOptions) {
async click(selector: string, options?: frames.WaitForOptions & input.ClickOptions) {
return this.mainFrame().click(selector, options);
}
dblclick(selector: string, options?: frames.WaitForOptions & input.MultiClickOptions) {
async dblclick(selector: string, options?: frames.WaitForOptions & input.MultiClickOptions) {
return this.mainFrame().dblclick(selector, options);
}
tripleclick(selector: string, options?: frames.WaitForOptions & input.MultiClickOptions) {
async tripleclick(selector: string, options?: frames.WaitForOptions & input.MultiClickOptions) {
return this.mainFrame().tripleclick(selector, options);
}
fill(selector: string, value: string, options?: frames.WaitForOptions) {
async fill(selector: string, value: string, options?: frames.WaitForOptions) {
return this.mainFrame().fill(selector, value, options);
}
focus(selector: string, options?: frames.WaitForOptions) {
async focus(selector: string, options?: frames.WaitForOptions) {
return this.mainFrame().focus(selector, options);
}
hover(selector: string, options?: frames.WaitForOptions & input.PointerActionOptions) {
async hover(selector: string, options?: frames.WaitForOptions & input.PointerActionOptions) {
return this.mainFrame().hover(selector, options);
}
select(selector: string, value: string | dom.ElementHandle | input.SelectOption | string[] | dom.ElementHandle[] | input.SelectOption[] | undefined, options?: frames.WaitForOptions): Promise<string[]> {
async select(selector: string, value: string | dom.ElementHandle | input.SelectOption | string[] | dom.ElementHandle[] | input.SelectOption[] | undefined, options?: frames.WaitForOptions): Promise<string[]> {
return this.mainFrame().select(selector, value, options);
}
type(selector: string, text: string, options?: frames.WaitForOptions & { delay?: number }) {
async type(selector: string, text: string, options?: frames.WaitForOptions & { delay?: number }) {
return this.mainFrame().type(selector, text, options);
}
waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options: { visible?: boolean; hidden?: boolean; timeout?: number; polling?: string | number; } = {}, ...args: any[]): Promise<js.JSHandle> {
async waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options: { visible?: boolean; hidden?: boolean; timeout?: number; polling?: string | number; } = {}, ...args: any[]): Promise<js.JSHandle> {
return this.mainFrame().waitFor(selectorOrFunctionOrTimeout, options, ...args);
}

View File

@ -14,15 +14,4 @@
* limitations under the License.
*/
const {helper} = require('./lib/helper');
const api = require('./lib/api');
for (const className in api.WebKit) {
// Playwright-web excludes certain classes from bundle, e.g. BrowserFetcher.
if (typeof api.WebKit[className] === 'function')
helper.installAsyncStackHooks(api.WebKit[className]);
}
const { WKPlaywright } = require('./lib/webkit/wkPlaywright');
const packageJson = require('./package.json');
module.exports = new WKPlaywright(__dirname, packageJson.playwright.webkit_revision);
module.exports = require('./index').playwright('webkit');