Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript Google Chrome扩展-弹出窗口不显示,可以';t检查背景页_Typescript_Google Chrome_Google Chrome Extension - Fatal编程技术网

Typescript Google Chrome扩展-弹出窗口不显示,可以';t检查背景页

Typescript Google Chrome扩展-弹出窗口不显示,可以';t检查背景页,typescript,google-chrome,google-chrome-extension,Typescript,Google Chrome,Google Chrome Extension,我正在开发一个Chrome扩展,它可以从活动选项卡中提取电子表格id,并通过gAPI操作Google表单。我无法确定此错误出现的具体情况。成功使用扩展后,弹出窗口无法再次打开,但扩展图标的背景变为灰色 解决此问题的唯一方法是在开发人员模式下重新加载扩展。在上传到Chrome Web Store进行测试的同一版本中,删除并再次添加扩展无法修复任何问题。错误收集器似乎捕捉不到任何错误,但当单击检查窗口标题栏中的Inspect views background.html时,第二个屏幕截图中出现了这个奇

我正在开发一个Chrome扩展,它可以从活动选项卡中提取电子表格id,并通过gAPI操作Google表单。我无法确定此错误出现的具体情况。成功使用扩展后,弹出窗口无法再次打开,但扩展图标的背景变为灰色

解决此问题的唯一方法是在开发人员模式下重新加载扩展。在上传到Chrome Web Store进行测试的同一版本中,删除并再次添加扩展无法修复任何问题。错误收集器似乎捕捉不到任何错误,但当单击检查窗口标题栏中的
Inspect views background.html
时,第二个屏幕截图中出现了这个奇怪的URI,而不是
DevTools-chrome-extension:///background.html
。重新加载后
DevTools-chrome-extension:///background.html
再次出现在标题栏中

试图通过在清单文件中的
page\u action
browser\u action
之间切换来解决此问题(在
background.ts中进行适当更改)。没有效果

background.ts

import {BackgroundServiceFoo} from "../BackgroundServiceFoo";
import {BackgroundServiceBar} from "../BackgroundServiceBar";

(window as any).backgroundServiceFoo = new BackgroundServiceFoo();
(window as any).backgroundServiceBar = new BackgroundServiceBar();

function tokenRefresh() {
  (window as any).backgroundServiceFoo.tokenRefresh()
    .catch(console.error);
}

chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
  chrome.declarativeContent.onPageChanged.addRules([{
    conditions: [new chrome.declarativeContent.PageStateMatcher({
      pageUrl: {urlContains: 'docs.google.com/spreadsheets'},
    })
    ],
    actions: [new chrome.declarativeContent.ShowPageAction()]
  }]);
});

chrome.alarms.onAlarm.addListener(tokenRefresh);
chrome.alarms.create("tokenRefresh", {periodInMinutes: 30});
tokenRefresh();
index.ts使用后台脚本提供的服务,如:

chrome.runtime.getBackgroundPage(backgroundPage => {
  ((backgroundPage as any).backgroundServiceBar as BackgroundServiceBar).doStuff();
});

1)当图标为灰色时,表示您的chrome.declarativeContent规则不匹配。这可能发生在使用HTML5历史API进行导航的现代网站上。常见的解决方法是切换到通用规则,例如,
hostEquals:'docs.google.com'
,2)chrome.declarativeContent应该在chrome.runtime.onInstalled中使用,如文档所示。您好@wOxxOm,感谢您的快速回答。1) 我写了“扩展图标的背景”-我的意思是这个灰色圆圈,当弹出窗口打开时成为图标的背景,而不是在“错误”选项卡上时图标的灰度版本。2) 我更改了它,但不幸的是,情况并非如此。听起来扩展卡在了无限循环中。在process manager中检查扩展的CPU消耗(操作系统或Chrome中的内置操作系统)。还可以尝试切换到消息传递,因为从另一个窗口直接调用函数可能有问题,而且无论如何调试起来都比较困难。1)当图标为灰色时,表示您的chrome.declarativeContent规则不匹配。这可能发生在使用HTML5历史API进行导航的现代网站上。常见的解决方法是切换到通用规则,例如,
hostEquals:'docs.google.com'
,2)chrome.declarativeContent应该在chrome.runtime.onInstalled中使用,如文档所示。您好@wOxxOm,感谢您的快速回答。1) 我写了“扩展图标的背景”-我的意思是这个灰色圆圈,当弹出窗口打开时成为图标的背景,而不是在“错误”选项卡上时图标的灰度版本。2) 我更改了它,但不幸的是,情况并非如此。听起来扩展卡在了无限循环中。在process manager中检查扩展的CPU消耗(操作系统或Chrome中的内置操作系统)。还可以尝试切换到消息传递,因为从另一个窗口直接调用函数可能有问题,而且无论如何,调试起来都比较困难。