【问题标题】:Chrome app install open site first runChrome 应用安装打开站点首次运行
【发布时间】:2016-08-27 13:38:06
【问题描述】:

我想在你安装应用后启动自动打开页面,怎么做?

我的代码

manifest.json

  {
  "manifest_version": 2,
  "name": "CNN",
  "version": "2.1",
  "permissions": ["webview", "pointerLock", "geolocation", "videoCapture"],
  "app": {
    "background": {
      "scripts": ["main.js"]
    }
  }
}

main.js

'use strict';
chrome.app.runtime.onLaunched.addListener(function() {
    window.open("https://google.com/");
});

【问题讨论】:

    标签: google-chrome google-chrome-devtools google-chrome-app


    【解决方案1】:

    使用不同的侦听器:chrome.runtime.onInstalledchrome.browser.openTab(自 Chrome 42 起):

    • manifest.json:将"browser" 添加到"permissions"
    • 后台脚本:

      chrome.app.runtime.onInstalled.addListener(function(details) {
          chrome.browser.openTab({url: 'https://www.example.com'});
      });
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      • 1970-01-01
      • 2012-06-07
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多