[英]Why does my very simple Chrome extension work on Mac but not PC?
I have written a very simple Chrome extension. 我写了一个非常简单的Chrome扩展程序。 It consists of this background page:
它由以下背景页面组成:
<script type="text/javascript">
chrome.tabs.onDetached.addListener(function(tabId, info){
var id = tabId;
chrome.tabs.get(id, function(tab) {
chrome.tabs.create({
windowId : info.oldWindowId,
index : info.oldPosition,
url : tab.url
});
});
});
</script>
All it does is allows you to pull a tab from a window without losing that tab and web address from the window. 它所做的就是允许您从窗口中拉出一个选项卡,而不会从窗口中丢失该选项卡和Web地址。 It basically duplicates the tab when you detach it.
它在拆分时基本上复制了选项卡。
The problem is that this works perfectly on a Mac but when I have tried it on two different Windows machines I get this error 问题是这在Mac上完美运行但是当我在两台不同的Windows机器上尝试它时,我得到了这个错误
background.html:7Uncaught TypeError: Cannot read property 'url' of undefined
It appears the tab object isn't being passed into the get
callback. 看来tab对象没有传递给
get
回调。 Does anyone know why this might be? 有谁知道为什么会这样? It obviously is when I run the code on a Mac.
很明显,当我在Mac上运行代码时。
So this is the only workaround that I can think of: 所以这是我能想到的唯一解决方法:
Behavior does seem wonky. 行为似乎很不稳定。 Perhaps file a bug report?
也许提交错误报告?
The problem is tab id changes after it is detached (old one doesn't exist anymore). 分离后的问题是标签ID更改(旧标签不再存在)。 Not sure whether it is an error or feature, but if it is inconsistent between Mac and PC then it is definitely an error (could be just performance difference - api method executes faster than tab detaches on a different computer).
不确定它是错误还是功能,但如果Mac和PC之间不一致则肯定是错误(可能只是性能差异 - api方法执行速度比不同计算机上的tab分离更快)。
mrtsherman was on right track with workaround, only instead of saving id
you should save info
as that id
doesn't mean anything anymore. mrtsherman是在正确的轨道上解决办法,而不是只节省的
id
,你应该保存info
作为id
不意味着什么了。 Then you would have all information to recreate a tab (use attached info
to get tab id, and saved detached info
to get old position and window). 然后,您将获得重新创建选项卡的所有信息(使用附加
info
获取选项卡ID,并保存分离info
以获取旧位置和窗口)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.