Skip to content

Commit

Permalink
Bug 1845150 - Update notificationbox usage for process hang notificat…
Browse files Browse the repository at this point in the history
…ion r=reusable-components-reviewers,tgiles

Can be tested locally using this snippet (which I think I took from a test...):

```js
let addonId = "test";
let policy = new WebExtensionPolicy({
    name: "Scapegoat",
    id: addonId,
    mozExtensionHostname: Services.uuid.generateUUID().number.slice(1, -1),
    baseURL: "file:///",
    allowedOrigins: new MatchPatternSet([]),
    localizeCallback() {},
});
policy.active = true;
ProcessHangMonitor.showNotification(window, { addonId, scriptBrowser: { browsingContext: { watchedByDevTools: false }} });
```

Differential Revision: https://phabricator.services.mozilla.com/D194316
  • Loading branch information
hannajones committed Jan 4, 2024
1 parent 2a3fe3b commit d2de50d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions browser/modules/ProcessHangMonitor.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export var ProcessHangMonitor = {
/**
* Show the notification for a hang.
*/
showNotification(win, report) {
async showNotification(win, report) {
let bundle = win.gNavigatorBundle;

let buttons = [
Expand Down Expand Up @@ -563,8 +563,10 @@ export var ProcessHangMonitor = {
});
}

win.gNotificationBox
.appendNotification(
// Sometimes the window may have closed already, in which case we won't
// be able to create a message bar so we need to handle any related errors.
try {
let hangNotification = await win.gNotificationBox.appendNotification(
"process-hang",
{
label: message,
Expand All @@ -577,8 +579,11 @@ export var ProcessHangMonitor = {
},
},
buttons
)
.setAttribute("notification-tag", notificationTag);
);
hangNotification.setAttribute("notification-tag", notificationTag);
} catch (err) {
console.warn(err);
}
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ add_task(async function waitForScriptTest() {
});

// Click the "Close" button this time, we shouldn't get a callback at all.
notification.currentNotification.closeButton.click();
notification.currentNotification.closeButtonEl.click();

// send another hang pulse, we should not get a notification here
Services.obs.notifyObservers(hangReport, "process-hang-report");
Expand Down

0 comments on commit d2de50d

Please sign in to comment.