Is there a universal browser variable where I can attach a listener to capture any errors that occur?

Currently, I am utilizing Selenium to navigate an AngularJS website and am keen on generating a comprehensive catalog of all errors that are thrown (my main focus is on lex errors). AngularJS provides access to $exceptionHandler for altering exception handling practices. However, I prefer not to make extensive modifications to the application code since these tests are conducted remotely.

In my case, with Firefox usage, attempting browser.manage().logs() results in failure. It seems like this issue is closely linked to Log console errors using protractor - refer to this Stack Overflow response.

I have experimentally employed window.onerror and

window.addEventListener('error', () => { ... });
, but unfortunately, neither of them captures the thrown error. I am beginning to suspect if there is some mechanism within AngularJS that obstructs propagation to the window.

This is what I aim to achieve:

window.thrownErrors = [];
[Some global object].throw = (error) => {
  console.error(error);
  window.thrownErrors.push(error);
}

throw new Error('throw test');
console.log(window.thrownErrors); // => ['throw test']

Answer №1

Make sure to utilize the useCapture option when including the event handler:

window.addEventListener('error', () => { ... }, true);

The third parameter can be a Boolean indicating whether events of this kind will be sent to the registered listener prior to being delivered to any EventTarget beneath it in the DOM hierarchy. During event bubbling through the tree, a listener set to use capture will not activate. Event capturing and bubbling are two methods for spreading events that occur in a nested element within another element where both elements have a handle for that specific event. The mode of event propagation determines the sequence in which elements receive the event. Refer to DOM Level 3 Events and JavaScript Event order for thorough clarification. If unspecified, useCapture defaults to false.

To learn more, check out:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generate a configuration file that allows for the reading and storage of modifications

Is there a way to create a configuration file (JSON) on the local file system using JavaScript where I can write and modify data without losing it when the application is restarted? Any suggestions or solutions for this problem? Thank you for your assista ...

Using Angular's $http service in a loop to asynchronously update data in a list

I have a list of IDs [1, 2, 3, 4] that I need to update, and once the updates are done, I want to reflect these changes in the UI displayed list. Each row in the list should be asynchronously updated, and as soon as an update for one ID is finished, I will ...

Obtain a masterpiece by creating a canvas in React

Greetings! I have developed a drawing app using react and I am looking for a way to capture what the user has drawn on the canvas when they release the mouse button. This process should repeat continuously until the user stops drawing. Can anyone suggest h ...

Detect the initial collision exclusively (Collision detection using raycasting)

I am currently working on a never-ending runner game where a character is positioned at (0,0) and can only move along the X-axis by using arrow keys or the mouse. There are two different types of objects moving from z = -10000 towards the character, and on ...

jQuery: Track mouse movement with a delay

I'm looking to create a div that follows cursor movement with a slight delay, similar to the effect seen on this website: In the example link provided, you can observe that the 'follower' has a brief delay in its animation. I attempted to ...

Tips on how to send responses back to Ajax and handle them individually for processing

When navigating from Page1 to Page2, an AJAX script is executed to load the content of Page2. Once on Page2, a mysqli database query is triggered. If the query is successful, I aim to send a success response back to the AJAX request and reload the page. H ...

Troubleshooting issues with Yii functional tests sampling

Recently, I delved into the Yii framework and began my journey of learning it. After generating the app skeleton using the yiic tool, I also installed PHPUnit and SeleniumRC. I decided to take a shot at running the functional tests provided by the skeleton ...

Guide to include particular data from 2 JSON objects into a freshly created JSON object

I have extracted the frequency of countries appearing in an object (displayed at the bottom). The challenge I am facing is that I require geocode information to associate with country names and their frequencies, so that I can accurately plot the results o ...

Assign values to variables in a JavaScript file using node.js

My tech stack includes node.js, express.js, and either pug or jade. Within my server, I inject a variable called pageId into a view. In the pug view, I utilize this variable using the following script: script. document.addEventListener('DOMConten ...

Manage each selenium node separately

My current project involves developing an automated test suite using Selenium. I want to create bots that I can control and use to test my webapp. While this task may seem straightforward, I have a specific requirement in mind. I want to be able to spawn S ...

Swapping the non-DOM element text with another content

Currently facing an issue in my project where I need to replace plain text inside a contenteditable element without being enclosed in a DOM element. Here, I'm extracting the textNode using window.getSelection(); and looking to perform a text replaceme ...

When the Escape key is pressed on the modal, it activates the escape event on the parent component

Welcome to the main page. "use client"; import React, { useEffect, useState } from "react"; import TestModal from "./TestModal"; const App = () => { const [isOpen, setIsOpen] = useState(false); const [isDiscardModalOp ...

What steps can I take to minimize the flashing of this fixed navigation bar?

My fixed navigation bar fades out when scrolling down the page and reappears when scrolling up, which all works well. However, I have noticed that if I do this very quickly with short movements, around 20 times, it doesn't have enough time to complete ...

UI.Bootstrap - incorrect formatting of text

I am facing an issue with my code where, when I add a string containing HTML code, it does not display in the correct HTML format. Below is a snippet from my code: vm_main.test = "Documents" + "internet site <b><a href='http://www.g ...

Automate Zoom join function with the help of puppeteer

Having trouble joining a Zoom meeting using Puppeteer, my code is not capturing the password field. Can anyone assist? Here is my code snippet: const puppeteer = require("puppeteer-extra"); const StealthPlugin = require("puppeteer-extra-plu ...

Incorporating a JavaScript npm module within a TypeScript webpack application

I am interested in incorporating the cesium-navigation JavaScript package into my project. The package can be installed via npm and node. However, my project utilizes webpack and TypeScript instead of plain JavaScript. Unfortunately, the package is not fou ...

Insert fresh div elements chronologically using jQuery

When a user clicks on the ".u-post-button" button, this script is triggered. It retrieves the content of the comment input field and posts it to the server as a JSON object. The returned data containing the comment information is then appended after the ...

Having trouble finding an element with Python Selenium after switching to a frame in Firefox browser?

I'm facing difficulty locating the element within the frame even after switching to the correct frame. Below is my code, error message, and HTML source. When I right-click on the frame and choose This Frame -> Show Only This Frame, I can find the e ...

Map on leaflet not showing up

I followed the tutorial at http://leafletjs.com/examples/quick-start/ as instructed. After downloading the css and js files to my local directory, I expected to see a map but all I get is a gray background. Can anyone advise me on what might be missing? T ...

Generate a collection of LatLng coordinates to represent a worldwide grid

I'm in search of a quick and easy solution, like a simple library or similar tool, that would allow me to call a function like createGlobalGrid(1000) and automatically generate a list of points on a geospatial surface, ensuring that each point is no m ...