- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个 chrome 扩展程序,它根据作为内容脚本注入(inject)的计时器的值重定向当前选项卡。后台脚本通过每隔一段时间轮询每个计时器来跟踪所有打开的选项卡的运行时间,如果在特定站点上花费的时间超过给定限制,则将事件选项卡重定向到插页式页面,并可以选择重置计时器并恢复以前的 URL。这是有效的,但是一旦计时器被重置一次,chrome.tabs.update()
会将事件选项卡重定向到 chrome-extension://invalid/
。我不确定为什么,甚至不知道如何诊断这里发生的事情。
这是它应该如何工作的,一步一步。首先,后台脚本中的 if
block 在时间到时被触发:
背景.js:
if (time_elapsed > time_limit) {
settings.restore_url = tab.url;
var timeup_url = chrome.extension.getURL('timeup.html');
update_icon("off");
chrome.tabs.update({url: timeup_url});
}
这会将当前选项卡的 url 保存到 settings
对象,从扩展目录中获取静态页面 timeup.html
的 URL,更新工具栏图标,并重定向当前选项卡到 timeup.html
。
timeup.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="bootstrap.css" type="text/css">
<style>
.hero-unit {
background-color: #ffffff;
text-align: center;
}
.icon {
vertical-align: middle;
}
.xlarge {
font-size: 20px;
}
</style>
<script src="timeup.js" type="text/javascript"></script>
<title>Tabminder</title>
</head>
<body>
<div class="container">
<div class="row-responsive">
<div class="hero-unit">
<h1>Don't get distracted!</h1>
<p>You've been browsing a timesink site for too long.</p>
<p>
<a class="btn btn-inverse btn-large xlarge" id="close-tabs"><img src="img/remove.png">
<span class="icon"> Close tab</span>
</a>
<a class="btn btn-danger btn-large xlarge" id="restart-timer"><img src="img/repeat.png">
<span class="icon"> Restart timer</span>
</a>
</p>
</div>
</div>
</div>
</body>
</html>
这很简单。连接到 'click'
事件监听器的两个按钮......
timeup.js:
document.addEventListener('DOMContentLoaded', function () {
document.getElementById("close-tabs").addEventListener('click', close_tabs);
document.getElementById("restart-timer").addEventListener('click', restart_timer);
});
var port = chrome.extension.connect();
function close_tabs () {
port.postMessage({close_tabs: true});
}
function restart_timer () {
port.postMessage({restart_timer: true});
}
#restart-timer
按钮调用 restart_timer()
,它将消息发送回内容脚本以重定向选项卡:
背景.js:
// Listen for connections from content scripts
chrome.extension.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
if (msg.name == "update") {
update_times(msg.update, port.sender.tab);
}
// Messages from timeup page:
if (msg.close_tabs === true) {
chrome.tabs.remove(port.sender.tab.id);
}
if (msg.restart_timer === true) {
var reset_hostname = get_location(settings.restore_url).hostname;
settings.elapsed_times[reset_hostname] = 0;
chrome.tabs.update({url: settings.restore_url});
}
});
});
这应该会重置存储在 settings
中的耗时并将选项卡重定向到 settings.restore_url
。这第一次正常工作,但一旦计时器被重置,似乎重定向到 chrome-extension://invalid/
。即使在第一次重置后,settings.restore_url
的正确值也会传递给 chrome.tabs.update()
,因此我不确定重定向的来源.这里出了什么问题?以后如何诊断此类错误?
最佳答案
正如@RobW 指出的那样,添加您需要主机页面访问的文件 web_accessible_resources
:
Manifest - Web Accessible Resources
An array of strings specifying the paths of packaged resources that are expected to be usable in the context of a web page. These paths are relative to the package root, and may contain wildcards.
...
These resources would then be available in a webpage via the URL
chrome-extension://[PACKAGE ID]/[PATH]
, which can be generated with theextension.getURL
method. Whitelisted resources are served with appropriate CORS headers, so they're available via mechanisms like XHR.A navigation from a web origin to an extension resource will be blocked unless the resource is listed as web accessible.
(仅摘录)
关于javascript - chrome.tabs.update() 重定向到 'chrome-extension://invalid/',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12359608/
我正在尝试向 iOS 应用商店提交更新。我要从 Buzztouch 应用程序转到 Sprite Kit 应用程序。我能够存档 Xcode 项目并提交它。该应用程序的状态为“上传已收到”,但大约一分钟后
我收到了这个奇怪的警告。我不确定是什么原因造成的。 .dia文件扩展名应该表示核心有向图图形文件。我没有添加,应用程序几乎没有用户界面。 最佳答案 我对这个答案并不满意,但我认为它可以帮助人们,直到找
下面用作 Uri 参数的程序集限定字符串在 XAML 中工作,但在代码中使用时会出现错误。 我尝试了各种 UriKind,结果都相同。我该如何解决这个问题? [Test] public void La
我正在开发一个 Angular 应用程序,目的是将其部署到移动设备和 Web 浏览器上。设置表单样式以显示无效输入时,我应该定位 Angular“ng-invalid”类还是 HTML5“:inval
我有一个在 Google App Engine 上运行的应用程序,它是 Android 应用程序的后端。它基本上是 Android 应用程序和在我自己的服务器上运行的 MySQL 数据库之间的桥梁。
我的代码是这样的: func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle,
I need to encrypt using Python with the A256GCM algorithm, and getting back a JWT that I need to
无法成功编译webpack并生成bundle.js文件。据我了解,我的 src_dir 和 dist_dir 变量能够指向正确的路径,但在尝试编译时我仍然始终收到两个错误之一。 配置对象无效。 Web
因此,当我在 postgres 上运行 regexp_matches 时收到一条错误消息,并且无法弄清楚如何通过它。它似乎在 regex101 等 reg_exp 测试站点上运行良好,但不幸的是在实际
这些是我正在使用的导入: import com.novell.ldap.*; import java.io.UnsupportedEncodingException; 我正在尝试进行一个非常简单的密码
在记录器函数的简写情况下,Pylint 提示 Invalid constant name "myprint"(invalid-name)。 # import from utils import get
我试图创建一个HTML输入标签,该标签仅接受以2种格式之一输入的数字,并拒绝所有其他输入。 我只想接受以下格式的数字,包括破折号: 1234-12 和 1234-12-12 注意:不是日期,而是合法的
我一直在尝试使用 Bootstrap 的表单样式处理 AngularJS 的电子邮件验证,并遇到了这个 CSS block 。 input:focus:required:invalid, textar
我正在编写一个程序,以确保我了解如何在 C 中正确实现单向链表。我目前正在哈佛的 CS50 类(class)中学习,并且使用本教程,因为 CS50 人员不解释链接详细列出数据结构:https://ww
此问题与询问同一消息的另一个问题不重复,但在另一个上下文中。这个问题的上下文只是关于上传截图图像和获取消息。 今天,我在将图片上传到 App Store Connect 时收到一条新消息: Inval
我的代码似乎运行良好,但当我滑动以删除 UITableView 中的一行时,应用程序崩溃并显示以下内容: 错误 LittleToDoApp[70390:4116002] *** Terminating
当我尝试发送语音消息时,总是收到无效的url错误。我正在使用Whisper将音频转换为文本,但由于某种原因,我似乎无法将文件传递给Whisper。当我在Java脚本中使用它而不是在TypeScrip中
我正在尝试在 flutter 上对 http 客户端进行单元测试。在模拟 http 和我的存储库类之后: void main() { MockHttpCLient mockHttpCLient;
我正在使用 pandoc 作为一个库,相关的代码片段是: module Lib ( latexDirToTex, latexToTxt ) where import qualified
我正在开发一个(相对简单的)Rails应用程序。我正在使用Devise gem处理用户 session 。每当我导航到localhost:3000/users/sign_in时,我都会看到Devise
我是一名优秀的程序员,十分优秀!