首页 > 解决方案 > 从注入的按钮打开页面时出现“被阻止”错误

问题描述

我有一个应用程序,它将向任何页面注入一个按钮,该按钮从我的 chrome 扩展程序链接到一个 HTML 页面。

页面打开,但我在页面上收到以下错误。

hnplemhgefnimaejljoniapgopbpfcad is blocked
Requests to the server have been blocked by an extension.
Try disabling your extensions.
ERR_BLOCKED_BY_CLIENT

但是,如果我刷新页面,页面就会开始工作。有人知道为什么吗?


示例应用程序:

内容.js

const body = document.querySelector('body');

const newNode = document.createElement('div');
newNode.setAttribute('style', 'position: fixed; padding: 15px; background: yellow; margin: 100px; z-index:99999;')
newNode.innerHTML = `<a href="chrome-extension://${chrome.runtime.id}/example.html" target="_BLANK">Example Page</a>`;

body.insertAdjacentElement('afterbegin', newNode);

例子.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Example</title>
</head>
<body>
    <h1>example</h1>
</body>
</html>

清单.json

{
  "name": "example",
  "version": "1.0",
  "description": "example",
  "manifest_version": 2,
  "permissions": ["declarativeContent", "contextMenus"],
  "content_scripts": [{
    "matches": ["<all_urls>"], 
    "js": ["content.js"]
  }]
}

标签: google-chromegoogle-chrome-extension

解决方案


推荐阅读