google-chrome-extension - Chrome 扩展在页面操作中显示弹出窗口
问题描述
我对 chrome 扩展浏览器和页面操作有点困惑。我的目标是有一个特定页面的弹出窗口。
manifest.json
:
{
"name": "Basic extention",
"version": "1.0",
"description": "Extention",
"permissions": [
"activeTab",
"declarativeContent",
"storage",
"tabs",
"*://www.google.com/*" ],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"page_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/icon16.png",
"32": "images/icon32.png",
"48": "images/icon64.png",
"128": "images/icon128.png"
}
},
"icons": {
"16": "images/icon16.png",
"32": "images/icon32.png",
"48": "images/icon64.png",
"128": "images/icon128.png"
},
"manifest_version": 2
}
background.js
:
'use strict';
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'https://www.google.com/*'},
})],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
});
popup.html
:
<!DOCTYPE html>
<html>
<head>
<style>
body{
background-color: green;
}
</style>
<title>Test extention</title>
</head>
<body>
Test
</body>
</html>
这是问题所在:
如果我
browser_action
在清单中使用,它会按预期工作。单击扩展图标后会显示弹出窗口。但是当我将其更改为 时
page_action
,弹出窗口不再显示。(鼠标左键单击打开与鼠标右键单击相同的菜单,而不是显示我的弹出窗口。)
我是否需要以某种方式手动触发弹出窗口?我在清单中缺少一些权限吗?我将不胜感激任何帮助或提示。
解决方案
您定义的条件hostEquals
不正确。hostEqual
它应该分为scheme
以下几种:
pageUrl: { hostEquals: 'www.google.com', schemes: ['https'] }
完成此操作后,它应该按定义工作。查看https://developer.chrome.com/extensions/declarativeContent中的规则部分
推荐阅读
- php - 使用 TCPDF 不显示会话消息
- javascript - 谷歌应用程序脚本获取范围以某种方式不起作用我做错了什么?
- html - 如何在boostrap 4中对齐容器中心的导航栏
- python - 将 Scip 与 CPLEX 或 Gurobi 链接
- xml - Oracle 12c,将 SOAP 响应存储到变量中或插入到表中
- python - 如何从元组列表的一部分中提取随机元素?
- php - 传递给 Illuminate\Database\Grammar::parameterize() 的 Laravel 工厂参数 1 必须是数组类型,给定字符串
- html - 嵌套 *ngFor 循环角度中(更改)事件输入的错误值
- windows - 无法使用带有 Windows 容器的 docker swarm 访问 Windows 机器上的共享存储
- ios - 浮动按钮并不总是在顶部可见