Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use runtime.onPerformanceWarning event for breakage reports (#2462)
The new runtime.onPerformanceWarning event is fired for extensions when the browser detects a runtime performance issue. This is so that extension developers can be notified and proactively investigate performance issues in their extensions. Initially, the event will be available with Firefox 124 and will fire only for serious content-script hangs[1]. (For those hangs, the user is also shown a warning banner[2].) In the future, the event will hopefully be available on more browsers, will include stack traces where possible and will fire under more conditions. For now, let's just include a basic `performanceWarning` flag with breakage reports, that indicates if the event fired for the tab in question. In the future, we can expand this as necessary to include details of stack traces and warning type and category. 1 - https://bugzilla.mozilla.org/show_bug.cgi?id=1861445 2 - "EXTENSION NAME" is slowing down Firefox. To speed up your browser, stop that extension. Learn more <Stop>
- Loading branch information
Showing
9 changed files
with
188 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import browser from 'webextension-polyfill' | ||
import tabManager from '../../../shared/js/background/tab-manager' | ||
import { TabState } from '../../../shared/js/background/classes/tab-state' | ||
import '../../../shared/js/background/events' | ||
|
||
async function createTab (id, url) { | ||
const tab = tabManager.create({ | ||
id, | ||
requestId: 123, | ||
url, | ||
status: 200 | ||
}) | ||
await TabState.done() | ||
return tab | ||
} | ||
|
||
describe('onPerformanceWarning event handler', () => { | ||
it('Sets the performanceWarning flag correctly', async () => { | ||
expect( | ||
browser.runtime.onPerformanceWarning._listeners.length | ||
).toEqual(1) | ||
const fireEvent = browser.runtime.onPerformanceWarning._listeners[0] | ||
|
||
let tab1 = await createTab(1, 'https://1.example') | ||
let tab2 = await createTab(2, 'https://2.example') | ||
|
||
// Flags should be false initially. | ||
expect(tab1.performanceWarning).toEqual(false) | ||
expect(tab2.performanceWarning).toEqual(false) | ||
|
||
// Flags should remain false if event fires for unknown/different tabs. | ||
fireEvent({ tabId: 99 }) | ||
fireEvent({ tabId: -1 }) | ||
fireEvent({ tabId: 0 }) | ||
fireEvent({}) | ||
|
||
expect(tab1.performanceWarning).toEqual(false) | ||
expect(tab2.performanceWarning).toEqual(false) | ||
|
||
// Flags should be set to true for the correct tab when the event fires. | ||
fireEvent({ tabId: 1 }) | ||
expect(tab1.performanceWarning).toEqual(true) | ||
expect(tab2.performanceWarning).toEqual(false) | ||
|
||
fireEvent({ tabId: 2 }) | ||
expect(tab1.performanceWarning).toEqual(true) | ||
expect(tab2.performanceWarning).toEqual(true) | ||
|
||
// Flags should be cleared when the tabs are navigated. | ||
tab1 = await createTab(1, 'https://second-1.example') | ||
expect(tab1.performanceWarning).toEqual(false) | ||
expect(tab2.performanceWarning).toEqual(true) | ||
|
||
tab2 = await createTab(2, 'https://second-2.example') | ||
expect(tab1.performanceWarning).toEqual(false) | ||
expect(tab2.performanceWarning).toEqual(false) | ||
|
||
// The flags should be set again when fired again after navigation. | ||
fireEvent({ tabId: 1 }) | ||
expect(tab1.performanceWarning).toEqual(true) | ||
expect(tab2.performanceWarning).toEqual(false) | ||
fireEvent({ tabId: 2 }) | ||
expect(tab1.performanceWarning).toEqual(true) | ||
expect(tab2.performanceWarning).toEqual(true) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters