Catch the JavaScript exceptions thrown in the browser.

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

Usage

.captureBrowserExceptions(onExceptionCallback)

Parameters

Name Type description
onExceptionCallback function

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

Example

 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('https://duckduckgo.com/');

     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