小编Nge*_*lus的帖子

如何编写将内容脚本应用于单页应用程序的 Chrome 扩展?

我目前正在编写一个扩展,该扩展将通过在元素的 href 中添加 tel: 并用如果需要的话,锚标记。

在过去的三天里,我一直在努力让它适用于我们公司用于联系人的单页应用程序。但是每当我将扩展程序加载到浏览器中然后重新启动浏览器时,它首先不会应用我的内容脚本。访问后我首先需要刷新页面。

我正在使用以下文件:

清单.json:

{
  "name": "testExtension",
  "short_name": "testExtension",
  "version": "1.0.0",
  "manifest_version": 2,
  "description": "Replace telephone numbers with clickable links.",
  "author": "Ngelus",
  "icons": {
    "16": "icons/icon16.png",
    "48": "icons/icon48.png",
    "128": "icons/icon128.png"
  },
  "browser_action": {
    "default_icon": "icons/icon48.png",
    "default_title": "testExtension"
  },
  "default_locale": "en",
  "permissions": [
    "tabs",
    "activeTab",
    "<all_urls>",
    "*://*.examplecontactsapp.de/*",
    "storage",
    "webRequest",
    "webNavigation"
  ],
  "content_scripts": [
    {
      "matches": [
        "*://web.examplecontactsapp.de/contacts",
        "*://web.examplecontactsapp.de/contacts*"
      ],
      "js": ["src/inject/contentscript.js"]
    }
  ],
  "background": {
    "scripts": ["src/bg/background.js"],
    "persistent": true
  }
}

Run Code Online (Sandbox Code Playgroud)

背景.js:

let currentUrl = '';
let …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome-extension single-page-application

0
推荐指数
1
解决办法
1543
查看次数