diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js index 2e4d45ee2..225d2f3c5 100644 --- a/app/scripts/lib/notification-manager.js +++ b/app/scripts/lib/notification-manager.js @@ -51,7 +51,12 @@ export default class NotificationManager extends EventEmitter { const lastFocused = await this.platform.getLastFocusedWindow(); // Position window in top right corner of lastFocused window. top = lastFocused.top; - left = lastFocused.left + (lastFocused.width - NOTIFICATION_WIDTH); + // - this is to make sure no error is triggered from polyfill + // error eg: Invalid value for bounds. Bounds must be at least 50% within visible screen space. + left = Math.max( + lastFocused.left + (lastFocused.width - NOTIFICATION_WIDTH), + 0, + ); } catch (_) { // The following properties are more than likely 0, due to being // opened from the background chrome process for the extension that diff --git a/app/scripts/lib/notification-manager.test.ts b/app/scripts/lib/notification-manager.test.ts index b3c44b249..bdbffbdaa 100644 --- a/app/scripts/lib/notification-manager.test.ts +++ b/app/scripts/lib/notification-manager.test.ts @@ -35,6 +35,7 @@ jest.mock('webextension-polyfill', () => { getAll: jest.fn(), create: jest.fn(), update: jest.fn(), + getLastFocused: jest.fn(), }, }; }); @@ -68,4 +69,28 @@ describe('Notification Manager', () => { expect(setCurrentPopupIdSpy).toHaveBeenCalledTimes(1); expect(setCurrentPopupIdSpy).toHaveBeenCalledWith(newPopupWindow.id); }); + + it('should not pass negative left value for extension window created from last focused window', async () => { + const newPopupWindow = generateMockWindow(); + setCurrentPopupIdSpy = jest.fn(); + const createSpy = jest.fn().mockReturnValue(newPopupWindow); + browser.windows.getAll.mockReturnValue([]); + browser.windows.create = createSpy; + browser.windows.getLastFocused.mockReturnValue({ + top: 0, + left: 0, + width: 120, // make sure this is smalled than NOTIFICATION_WIDTH + }); + currentPopupId = undefined; + await notificationManager.showPopup(setCurrentPopupIdSpy, currentPopupId); + expect(createSpy).toHaveBeenCalledTimes(1); + expect(createSpy).toHaveBeenCalledWith({ + height: 620, + left: 0, // this is critical, means error related to polyfill is not triggered + top: 0, + type: 'popup', + url: 'notification.html', + width: 360, + }); + }); });