Window.focus: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(document window.focus)
(No difference)

Revision as of 07:37, 24 August 2021

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");
});