mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(worker): implement pageerror event from a worker (#2795)
Fixes #2761
This commit is contained in:
parent
811415bc8c
commit
aae73f5fd7
@ -102,7 +102,7 @@ class Page extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const session = client._createSession(event.targetInfo.type, event.sessionId);
|
const session = client._createSession(event.targetInfo.type, event.sessionId);
|
||||||
const worker = new Worker(session, event.targetInfo.url, this._addConsoleMessage.bind(this));
|
const worker = new Worker(session, event.targetInfo.url, this._addConsoleMessage.bind(this), this._handleException.bind(this));
|
||||||
this._workers.set(event.sessionId, worker);
|
this._workers.set(event.sessionId, worker);
|
||||||
this.emit(Page.Events.WorkerCreated, worker);
|
this.emit(Page.Events.WorkerCreated, worker);
|
||||||
|
|
||||||
|
@ -22,8 +22,9 @@ class Worker extends EventEmitter {
|
|||||||
* @param {Puppeteer.CDPSession} client
|
* @param {Puppeteer.CDPSession} client
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
* @param {function(!string, !Array<!JSHandle>)} consoleAPICalled
|
* @param {function(!string, !Array<!JSHandle>)} consoleAPICalled
|
||||||
|
* @param {function(!Protocol.Runtime.ExceptionDetails)} exceptionThrown
|
||||||
*/
|
*/
|
||||||
constructor(client, url, consoleAPICalled) {
|
constructor(client, url, consoleAPICalled, exceptionThrown) {
|
||||||
super();
|
super();
|
||||||
this._client = client;
|
this._client = client;
|
||||||
this._url = url;
|
this._url = url;
|
||||||
@ -39,6 +40,7 @@ class Worker extends EventEmitter {
|
|||||||
this._client.send('Runtime.enable', {}).catch(debugError);
|
this._client.send('Runtime.enable', {}).catch(debugError);
|
||||||
|
|
||||||
this._client.on('Runtime.consoleAPICalled', event => consoleAPICalled(event.type, event.args.map(jsHandleFactory)));
|
this._client.on('Runtime.consoleAPICalled', event => consoleAPICalled(event.type, event.args.map(jsHandleFactory)));
|
||||||
|
this._client.on('Runtime.exceptionThrown', exception => exceptionThrown(exception.exceptionDetails));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,5 +48,11 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
const worker = await workerCreatedPromise;
|
const worker = await workerCreatedPromise;
|
||||||
expect(await (await worker.executionContext()).evaluate('1+1')).toBe(2);
|
expect(await (await worker.executionContext()).evaluate('1+1')).toBe(2);
|
||||||
});
|
});
|
||||||
|
it('should report errors', async function({page}) {
|
||||||
|
const errorPromise = new Promise(x => page.on('pageerror', x));
|
||||||
|
await page.evaluate(() => new Worker(`data:text/javascript, throw new Error('this is my error');`));
|
||||||
|
const errorLog = await errorPromise;
|
||||||
|
expect(errorLog.message).toContain('this is my error');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user