How can I make a chrome packaged app which runs in fullscreen at startup?

后端 未结 6 903
悲&欢浪女
悲&欢浪女 2021-02-14 06:39

Currently it seems that the fullscreen ability can only be activated from a user action (mouse/keyboard event). Is there a way to circumvent this?

相关标签:
6条回答
  • 2021-02-14 07:25

    Check out https://plus.google.com/100132233764003563318/posts/2SuD7MVd8mG referring to recently landed changelist https://chromiumcodereview.appspot.com/12205002. You can lift sample code from either of those sources:

    document.body.addEventListener('click', function() {
      document.body.webkitRequestFullscreen();
    });
    

    Make sure in your manifest you're requesting the "fullscreen" permission and that you're testing on a sufficiently recent Chrome build (beta channel ought to have this feature by now, and dev definitely does).

    Your question specifically refers to packaged apps, but in case anyone reading this answer missed this, this will work only with Chrome packaged apps.

    0 讨论(0)
  • 2021-02-14 07:27

    I have got it working with below code

    chrome.app.runtime.onLaunched.addListener(function() {
        chrome.app.window.create('index.html', {
        'width': 1024,
        'height': 768
    },
    function(win) {
        win.maximize();
    });
    });
    
    0 讨论(0)
  • 2021-02-14 07:28

    Edit: Per BeardFist's comment, my original answer was wrong on two fronts. You can do this on a Chrome Extension (which this is tagged as), but probably not on a packaged app.

    For extensions you can make it go fullscreen using the state:"fullscreen" option, which can be applied with chrome.window.update. The code below chains the creation of the window via chrome.windows.create with chrome.window.update. In my experiments you could not set the fullscreen state directly through the window creation.

    chrome.windows.create(
      {url:"PATH/TO/POPUP"}, 
        function(newWindow) {
            chrome.windows.update(newWindow.id, {state:"fullscreen"})
    });
    
    0 讨论(0)
  • 2021-02-14 07:35

    You can use the HTML5 Fullscreen API, which requires a user action:

    button.addEventListener('click', function() {
      document.body.webkitRequestFullscreen();
    });
    

    or the more "app-y" way using the AppWindow object, which doesn't require a user action:

    chrome.app.window.current().fullscreen();
    

    Both need the "fullscreen" permission in the manifest.json.

    0 讨论(0)
  • 2021-02-14 07:39

    main.js

    chrome.app.runtime.onLaunched.addListener(function() {
      chrome.app.window.create('index.html',{},function(window) {
        window.fullscreen();
      });
    });
    

    manifest.json

    {
      ...
      "manifest_version": 2,
      "minimum_chrome_version": "23",
      "app": {
        "background": {
          "scripts": ["main.js"]
        }
      },
      "permissions": ["fullscreen"]
    }
    
    0 讨论(0)
  • 2021-02-14 07:44

    Now, you can just add the state:"fullscreen" property on your main .js:

    chrome.app.runtime.onLaunched.addListener(
        function() {
            chrome.app.window.create('index.html',
                {
                    state: "fullscreen",
                }
            );
        }
    );
    

    Make sure you don't add resizable: false or bounds properties, and you add a "fullscreen" permision on the manifest.json.

    {
        ...
        "permissions": [
            ...
            "fullscreen"
        ]
    }
    
    0 讨论(0)
提交回复
热议问题