Window.focus: Difference between revisions
From GreaseSpot Wiki
Jump to navigationJump to search
document window.focus |
m add sample class to code block |
||
Line 10: | Line 10: | ||
== Examples == | == Examples == | ||
<pre> | <pre class="sample"> | ||
GM.notification("you can switch to the tab", "focus", '', () => { | GM.notification("you can switch to the tab", "focus", '', () => { | ||
window.focus(); | window.focus(); |
Latest revision as of 07:38, 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"); });