Catch the JavaScript exceptions thrown in the browser.

captureBrowserExceptions() is only available when using Chrome or Edge drivers.




Name Type description
onExceptionCallback function

Callback function called whenever a new exception is thrown in the browser.


 describe('catch browser exceptions', function() {
   it('captures the js exceptions thrown in the browser', async function() {
     await browser.captureBrowserExceptions((event) => {
       console.log('>>> Exception:', event);

     await browser.navigateTo('');

     const searchBoxElement = await browser.findElement('input[name=q]');
     await browser.executeScript(function(_searchBoxElement) {
       _searchBoxElement.setAttribute('onclick', 'throw new Error("Hello world!")');
     }, [searchBoxElement]);

     await browser.elementIdClick(searchBoxElement.getId());

Recommended content