如何针对Chromium浏览器扩展程序中的错误(如果以开发人员模式在本地安装该错误) [英] How to aim a bug in Chromium browser extension that there won't be if installed locally in Dev mode

查看:53
本文介绍了如何针对Chromium浏览器扩展程序中的错误(如果以开发人员模式在本地安装该错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚测试了我的Chrome插件 https://chrome.google.com/webstore/detail/soft-screen/oecaicengbgemdbdklmajocogdjjgnda 在正式安装之后(即通过CWS(Chrome网上应用店)),但突然感到惊讶,它无法正常工作.我一直通过在Dev模式下本地安装来使用它,例如,将安装并位于 {Chrome目录} \ User Data \ Default \ Extensions \ oecaicengbgemdbdklmajocogdjjgnda 的加载项复制到另一个目录,然后重新安装通过将其拖动到 chrome://extension URL(在开发人员"模式处于启用状态时)进行操作.然后,我不得不从其 manifest.json 中删除 key ,然后禁用通过CWS安装的第一个.我可以在本地开发人员模式和CWS扩展之间切换该扩展,以防止同时安装并启用两个相互冲突的相同扩展.

I've just tested my Chrome addon https://chrome.google.com/webstore/detail/soft-screen/oecaicengbgemdbdklmajocogdjjgnda after installing it officially, i.e. via CWS (Chrome Web Store), but was suddenly surprised that it's not working. I've always used it by installing it locally in Dev mode, i.e. by copying the addon installed and located at {The Chrome directory}\User Data\Default\Extensions\oecaicengbgemdbdklmajocogdjjgnda to another directory and then reinstall it by dragging it to the chrome://extension URL (while Developer mode is on). I then had to remove the key from its manifest.json and then disable the first one that was installed via CWS. I could toggle the extension between local Developer mode and CWS extension to prevent two conflicting identical extensions installed and enabled at once.

区别非常明显,即在使用CWS(添加到Chrome")安装中不起作用,而仅在本地开发人员模式下起作用.

The difference is very conspicuous in which it does not work in using the CWS ("Add to Chrome") installation, but it simply works in local Developer mode.

您能做些和我一样的事情来帮助我吗,也许您比我更精通我,以便我能够修复该错误并解决问题.

Can you please help me out by doing the same as I did and may you be more knowledgeable than me so that I will be able to fix the bug and solve the problem.

推荐答案

这是一个常见的问题:您正在使用非持久性后台脚本(manifest.json中的持久性:false )和chrome.runtime.onInstalled侦听器,您可以在其中注册一些侦听器.

This is a common problem: you're using a non-persistent background script ("persistent":false in manifest.json) and chrome.runtime.onInstalled listener where you register some listeners.

这是错误的,因为onInstalled仅在正常扩展的安装/更新时触发,但是非持久性后台脚本应在全局上下文中注册其侦听器,以便每次恢复非持久性后台脚本时都可以更新它们.

This is wrong because onInstalled is triggered only on installs/updates for a normal extension, but a non-persistent background script should register its listeners in the global context so that they are renewed every time the non-persistent background script is resumed.

它仅在开发人员模式下对您有效,因为Chrome会将重新加载扩展程序视为onInstalled中报告的更新事件.也许您已经为后台脚本打开了devtools,这阻止了它在5秒钟内被卸载,这是它的标准行为.

It worked for you in developer mode only because reloading an extension is treated by Chrome as an update event reported in onInstalled. Or maybe you had devtools open for your background script which prevented it from unloading in 5 seconds, which is its standard behavior.

TL; DR将chrome.browserAction.onClicked注册从chrome.runtime.onInstalled中移出:

TL;DR Move chrome.browserAction.onClicked registration out of chrome.runtime.onInstalled:

chrome.runtime.onInstalled.addListener(function(info) {
  // code that should run on install/update
  // ...............
});

chrome.browserAction.onClicked.addListener(function(tab) {
  // code that should run on clicking the extension icon
  // ...............
});

这篇关于如何针对Chromium浏览器扩展程序中的错误(如果以开发人员模式在本地安装该错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆