karma-runner / karma-runner/karma
Clicking debug link with useIframe: false spawns extra windows
- Dominant language
- JavaScript
- Stars
- 12k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
### Expected behaviour
No new tabs open
### Actual behaviour
A new tab opens (pointing to `about: blank`) when the test adapter calls `__karma__.error()`
### Environment Details
- Karma version: 1.7.1
- Relevant part of your `karma.config.js` file:
```js
config.set({
client: {
useIframe: false,
},
});
```
### Steps to reproduce the behaviour
1. Click the debug link in the main Karma page
2. Have a test fail in a way that calls `__karma__.error()` (I discovered this bug using an internal adapter).
### Underlying cause
The debug page loads `context.js`, which defines `__karma__` methods that call through to the parent page if available. When the debug page is loaded by clicking the `Debug` link in the main page,
Under normal (iframe-based) circumstances, this is harmless; it just makes the parent page do extra work.
However, with `useIframe: false`, this makes `complete()` (called by `error()`) open a new window as part of `clearContext()`.
To fix, make `debug.js` set `window.__karma__.error` to override the default behavior. It should probably log and rethrow the error; however, if the test adapter calls `__karma__.error()` from `window.onerror`, this will make an infinite loop.
Fixing #2975 will also mask this issue.
Contributor guide
Research direction
Start in debug.js and context.js, focusing on how the debug page defines window.__karma__.error and how complete() reaches clearContext() with useIframe: false. Reproduce the failure by clicking Debug and triggering __karma__.error() from the adapter. Done means no extra about:blank tab opens and the override does not recurse when called from window.onerror.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100