I am overwriting console.log so that I can observe an event and take action on it.
This is done via go, when I launch a new tab by clicking a link, so it happens quickly.
When I observe that event, I take an action and then I'm good. Now, the problem comes into play when I close that tab and repeat the process (open a new tab). The problem is that it always fails after the initial attempt and always succeeds on the first attempt (new browser session).
AFAIK, window variable refers to the current tab and not the entire browser "window". I understand this could be related to timing and the only thing I can surmise is that possibly it is quicker to attach to the window the first time than subsequent times and the specific event is missed.
Whenever I look at window.capturedLogs, the size is substantially smaller for later attempts which is strange.
1. What would cause this to fail after the initial attempt?
2. Are there any alternatives to this approach that would be more reliable? I am not a JavaScript developer - I primarily do Java, so this was the first thing that worked that I stumbled upon ...
This is done via go, when I launch a new tab by clicking a link, so it happens quickly.
JavaScript:
window.originalLog = console.log;
window.capturedLogs = [];
console.log = (...args) => {
window.capturedLogs.push(...args);
originalLog(...args);
When I observe that event, I take an action and then I'm good. Now, the problem comes into play when I close that tab and repeat the process (open a new tab). The problem is that it always fails after the initial attempt and always succeeds on the first attempt (new browser session).
AFAIK, window variable refers to the current tab and not the entire browser "window". I understand this could be related to timing and the only thing I can surmise is that possibly it is quicker to attach to the window the first time than subsequent times and the specific event is missed.
Whenever I look at window.capturedLogs, the size is substantially smaller for later attempts which is strange.
1. What would cause this to fail after the initial attempt?
2. Are there any alternatives to this approach that would be more reliable? I am not a JavaScript developer - I primarily do Java, so this was the first thing that worked that I stumbled upon ...
Last edited: