Going into full screen triggers chrome.system.display.onDisplayChanged

184 views
Skip to first unread message

tea

unread,
Jan 11, 2022, 10:18:08 AM1/11/22
to Chromium Extensions
Hi friends,
I am on MV2.
I am using chrome.system.display.onDisplayChanged event listener to figure out when the user adds or removes a monitor. However, this listener is triggering when I put the browser in full screen. 
No where in the docs is this called out. Any idea how I can get around this so that user going into full screen does not detect this or I can determine that it is the laptop size change that caused this?

thank you

Cuyler Stuwe

unread,
Jan 11, 2022, 11:31:30 AM1/11/22
to tea, Chromium Extensions
Sounds like you might be getting into OS implementation details. What OS?

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/986c6eda-8336-4f8f-8506-e18d379415bfn%40chromium.org.

hrg...@gmail.com

unread,
Jan 11, 2022, 1:18:33 PM1/11/22
to Chromium Extensions, salem...@gmail.com, Chromium Extensions, tea
onDisplayChanged is triggered whenever the data given by system.display.getInfo() changes.

For example, the event will fire if you change your DPI settings or scaling factor, resolution, color depth, etc..
It will also fire when the desktop's work area changes due to toolbars or widgets being added or removed from the desktop.

If you want to detect when a monitor is being added or removed, you have to compare the data given by display.getInfo() with that of a previous call to the same function.

tea

unread,
Jan 11, 2022, 2:20:48 PM1/11/22
to Chromium Extensions, salem...@gmail.com, Chromium Extensions, tea
Windows and Mac. I think the reply regarding having to do some form of bookkeeping using display.getInfo() is the solution I was thinking of. As much as I dislike keeping state, I am not sure that there is a better way. However, I welcome suggestions

hrg...@gmail.com

unread,
Jan 12, 2022, 12:33:36 PM1/12/22
to Chromium Extensions, tea, salem...@gmail.com, Chromium Extensions
This is yet another use case that becomes tediously complicated because of MV3.
The solution is to use a generic mechanism for all persistent variables. That way you can reuse that mechanism throughout your entire code, so there's no additional implementation cost of keeping state whenever you need to (such as in your case).

The way I do it is to keep all persistent variables in a global object with a setter method which automatically saves the set values to persisten storage.
That way I can use the variables in this global object as regular variables in any synchronous code.

tea

unread,
Jan 14, 2022, 4:27:51 PM1/14/22
to Chromium Extensions, hrg...@gmail.com, tea, salem...@gmail.com, Chromium Extensions
great recommendation thank you.
In my case the bookkeeping for this variable is just in this one class. However, there are other cases where I have globals that the entire extension uses. Thanks for the great suggestion.

Reply all
Reply to author
Forward
0 new messages