diff --git a/src/frames.ts b/src/frames.ts index 2832cdce5b..15d35164b3 100644 --- a/src/frames.ts +++ b/src/frames.ts @@ -685,7 +685,7 @@ export class Frame { let result; if (path !== null) { let contents = await util.promisify(fs.readFile)(path, 'utf8'); - contents += '//# sourceURL=' + path.replace(/\n/g, ''); + contents += '\n//# sourceURL=' + path.replace(/\n/g, ''); result = (await context.evaluateHandleInternal(addScriptContent, { content: contents, type })).asElement()!; } else { result = (await context.evaluateHandleInternal(addScriptContent, { content: content!, type })).asElement()!; @@ -740,7 +740,7 @@ export class Frame { if (path !== null) { let contents = await util.promisify(fs.readFile)(path, 'utf8'); - contents += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/'; + contents += '\n/*# sourceURL=' + path.replace(/\n/g, '') + '*/'; return (await context.evaluateHandleInternal(addStyleContent, contents)).asElement()!; } diff --git a/src/rpc/client/browserContext.ts b/src/rpc/client/browserContext.ts index e433bfb59c..ad1e321ff2 100644 --- a/src/rpc/client/browserContext.ts +++ b/src/rpc/client/browserContext.ts @@ -26,7 +26,6 @@ import { Browser } from './browser'; import { Events } from '../../events'; import { TimeoutSettings } from '../../timeoutSettings'; import { Waiter } from './waiter'; -import { TimeoutError } from '../../errors'; import { headersObjectToArray } from '../serializers'; export class BrowserContext extends ChannelOwner { @@ -207,7 +206,7 @@ export class BrowserContext extends ChannelOwner { }); } - private _setupNavigationWaiter(): Waiter { + private _setupNavigationWaiter(options: types.TimeoutOptions): Waiter { const waiter = new Waiter(); waiter.rejectOnEvent(this._page!, Events.Page.Close, new Error('Navigation failed because page was closed!')); waiter.rejectOnEvent(this._page!, Events.Page.Crash, new Error('Navigation failed because page crashed!')); waiter.rejectOnEvent(this._page!, Events.Page.FrameDetached, new Error('Navigating frame was detached!'), frame => frame === this); + const timeout = this._page!._timeoutSettings.navigationTimeout(options); + waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded.`); + return waiter; } async waitForNavigation(options: types.WaitForNavigationOptions = {}): Promise { return this._wrapApiCall(this._apiName('waitForNavigation'), async () => { const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil); - const timeout = this._page!._timeoutSettings.navigationTimeout(options); - const waiter = this._setupNavigationWaiter(); - waiter.rejectOnTimeout(timeout, new TimeoutError(`Timeout ${timeout}ms exceeded.`)); + const waiter = this._setupNavigationWaiter(options); const toUrl = typeof options.url === 'string' ? ` to "${options.url}"` : ''; waiter.log(`waiting for navigation${toUrl} until "${waitUntil}"`); @@ -144,9 +144,7 @@ export class Frame extends ChannelOwner { if (this._loadStates.has(state)) return; return this._wrapApiCall(this._apiName('waitForLoadState'), async () => { - const timeout = this._page!._timeoutSettings.navigationTimeout(options); - const waiter = this._setupNavigationWaiter(); - waiter.rejectOnTimeout(timeout, new TimeoutError(`Timeout ${timeout}ms exceeded.`)); + const waiter = this._setupNavigationWaiter(options); await waiter.waitForEvent(this._eventEmitter, 'loadstate', s => { waiter.log(` "${s}" event fired`); return s === state; diff --git a/src/rpc/client/page.ts b/src/rpc/client/page.ts index c6d15d81da..b5519c02ae 100644 --- a/src/rpc/client/page.ts +++ b/src/rpc/client/page.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { TimeoutError } from '../../errors'; import { Events } from '../../events'; import { assert, assertMaxArguments, helper, Listener } from '../../helper'; import { TimeoutSettings } from '../../timeoutSettings'; @@ -335,7 +334,7 @@ export class Page extends ChannelOwner { const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate); const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate; const waiter = new Waiter(); - waiter.rejectOnTimeout(timeout, new TimeoutError(`Timeout while waiting for event "${event}"`)); + waiter.rejectOnTimeout(timeout, `Timeout while waiting for event "${event}"`); if (event !== Events.Page.Crash) waiter.rejectOnEvent(this, Events.Page.Crash, new Error('Page crashed')); if (event !== Events.Page.Close) diff --git a/src/rpc/client/waiter.ts b/src/rpc/client/waiter.ts index a9e062cb4d..471188e17b 100644 --- a/src/rpc/client/waiter.ts +++ b/src/rpc/client/waiter.ts @@ -16,6 +16,7 @@ import { EventEmitter } from 'events'; import { rewriteErrorMessage } from '../../utils/stackTrace'; +import { TimeoutError } from '../../errors'; export class Waiter { private _dispose: (() => void)[] = []; @@ -33,11 +34,11 @@ export class Waiter { this._rejectOn(promise.then(() => { throw error; }), dispose); } - rejectOnTimeout(timeout: number, error: Error) { + rejectOnTimeout(timeout: number, message: string) { if (!timeout) return; const { promise, dispose } = waitForTimeout(timeout); - this._rejectOn(promise.then(() => { throw error; }), dispose); + this._rejectOn(promise.then(() => { throw new TimeoutError(message); }), dispose); } dispose() { diff --git a/test/page.jest.js b/test/page.jest.js index 2c27e2525f..c5712d6dcc 100644 --- a/test/page.jest.js +++ b/test/page.jest.js @@ -979,13 +979,13 @@ describe('Page.selectOption', function() { }); it('should return [] on no matched values', async({page, server}) => { await page.goto(server.PREFIX + '/input/select.html'); - const result = await page.selectOption('select','42','abc'); + const result = await page.selectOption('select', ['42','abc']); expect(result).toEqual([]); }); it('should return an array of matched values', async({page, server}) => { await page.goto(server.PREFIX + '/input/select.html'); await page.evaluate(() => makeMultiple()); - const result = await page.selectOption('select','blue','black','magenta'); + const result = await page.selectOption('select', ['blue','black','magenta']); expect(result.reduce((accumulator,current) => ['blue', 'black', 'magenta'].includes(current) && accumulator, true)).toEqual(true); }); it('should return an array of one element when multiple is not set', async({page, server}) => {