首页 > 解决方案 > 在 chrome 中创建新选项卡时,我想重定向到自定义 html 页面

问题描述

我正在开发一个 chrome 扩展。创建新选项卡时,我想重定向到自定义 html 页面。

这是 process.js 文件。

    chrome.tabs.onCreated.addListener(function() {
        alert("hello");
        window.open('https://ucsc.cmb.ac.lk/', '_self', false);
    });

这是 manifest.json 文件。

    {
        "manifest_version": 2,
         "name": "xxx",
        "version": "1.0",
        "description": "xxx",
        "icons": {
            "128": "icon128.png",
            "48": "icon48.png",
            "16": "icon16.png"
        },
        "browser_action": {
            "default_icon": "icon16.png",
            "default_popup": "popup.html"
        },



        "background": {
            "scripts": ["process.js"],
            "presistent": true

        },

        "permissions": [
            "storage",
            "notifications",
            "contextMenus",
            "tabs",
            "activeTab",
            "http://*/",
            "https://*/"
        ]
    }

警报正在工作。但它没有加载页面。

标签: javascriptapigoogle-chrome

解决方案


您可能正在寻找Override Pages

将此代码添加到您的清单文件中:

"chrome_url_overrides" : {
   "pageToOverride": "myPage.html"
},

推荐阅读