google-chrome - 从注入的按钮打开页面时出现“被阻止”错误
问题描述
我有一个应用程序,它将向任何页面注入一个按钮,该按钮从我的 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"]
}]
}
解决方案
推荐阅读
- r - 如何密码保护从数据框中导出的 Excel?
- azure-data-factory - 映射数据流公共数据模型源连接器日期时间/时间戳列无效?
- javascript - 单击复选框时,如何在单个字段上使用 jquery 禁用客户端验证?
- c# - code_verifier 与 PKCE 授权请求中提供的 code_challenge 不匹配
- javascript - 每次点击如何在js中动态添加字体真棒图标
- eclipse - Eclipse:不包含 JNI_CreateJavaVM 符号”
- spring - 如何检查我的服务中的“elasticsearch is down”条件?
- eclipse - 无法在 WildFly 21 上使用 JSF 2.2 访问 CDI 支持 Bean
- php - php中的活动目录身份验证
- reactjs - 使用 useState 或 useRef (React) 将值清除到输入中