Window.focus

From GreaseSpot Wiki
Revision as of 03:38, 24 August 2021 by Gholk (talk | contribs) (add sample class to code block)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Description

Calling window.focus() will make browser switch the tab of User script, without registration of service worker. This API does not require @grant in metadata block.

Calling this function in normal JavaScript context in invalid because the permission to focus a window require a service worker. See WindowClient.focus.

Examples

GM.notification("you can switch to the tab", "focus", '', () => {
  window.focus();
  alert("you are in the tab now");
});