'Chrome extension's popup user activation

Background

There are some Web APIs that are "gated by user activation". An example of such an API is the Fullscreen API.

Question

Default popup page window is not treated as being user activated. Why is that? I would expect that if a user clicked the toolbar icon to open the popup the code will be treated as user activated.

Example

manifest.json

{
    "name": "Test",
    "description": "Test"
    "version": "1.0.0",
    "manifest_version": 3,
    "action": {
        "default_popup": "popup.html",
    }

}

popup.html

<html>
   <body>
       <script src="popup.js"></script>
   </body>
</html>

popup.js

document.body.requestFullscreen();

The above code won't work. In Chrome I will get following warning: Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture.



Solution 1:[1]

this is not the best practice, but might be a workaround

  1. when clicking popup, without opening the popup on the toolbar, use chrome.action.onClick to get the event and open the popup in the new tab, and run document.body.requestFullscreen();
  2. when full screen exits, remove that tab

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 thusimon