问题描述
我正在调试基于XUL的Firefox扩展程序,Firefox 46已经被Firefox 46发行。
当我运行扩展名时,显示:
chrome URI无效:/
既没有行号也没有堆栈跟踪。 >
在网络论坛上, ChromeBug可以用于此。然后,我尝试了最新的稳定版本的ChromeBug(1.7.2),但是自oct以来还没有更新。 2014年,似乎与最近的Firefox版本不兼容。
由于扩展名是旧式,因此我无法使用,因此我使用了,但不显示例外。
考虑到扩展的行数,在代码中漫游不是一个选择。任何想法如何获得堆栈跟踪?
当您在浏览器控制台中获得这种类型的错误时,关于什么是导致错误的信息很少可能是JavaScript中的错误,甚至可能不在你的代码内。在这种情况下,不可能获得JavaScript堆栈跟踪,因为它不存在。
这样的事情通常是由XUL或HTML中使用的问题引起的打开的弹出式窗口或选项卡。您的加载项将打开一个包含 chrome://restclient/content/restclient.html 的内容的选项卡。将该文件替换为没有内容的HTML文档会使错误消失。
使用对该文件内容的二进制搜索(注释/删除渐进半部分的文件,并测试以查看错误是否仍然存在)A)确认错误是在那里和B)是什么导致错误,导致确定以下行导致错误显示在浏览器控制台(第197行):
< input class =span5style =width:-moz-calc % - 1em)!important; type =passwordname =passwordautocomplete =onplaceholder =Password>
更多的测试显示,当键入
不是密码
。将原始HTML文档复制到可以使用文件轻松访问的地方:
URL,在打开文档时,浏览器控制台中不会出现此类错误。 p>
因此,结论是Mozilla的代码中的错误< input type =password>
从 chrome加载:
URI。
查找无效的 chrome:
没有堆栈跟踪的代码中的URI:
如果在HTML或XUL文件中找不到问题,则需要查看 chrome:
您的加载项中使用的URI,以查找可能的原因。
chrome:
URI有一些属性,我们可以利用这些属性来跟踪这样一个问题:
-
chrome:
URI通常是静态。 -
chrome:
URI通常以chrome:\\packageName\ {content,皮肤,区域设置}
- 您的 chrome.manifest 文件定义了什么
chrome:
- 其他 chrome.manifest 文件定义什么
chrome:
URI可以在您的附加组件/包之外有效。
所以首先看看你的chrome.manifest 文件:
内容restclient内容/
资源restclient ./
overlay chrome://browser/content/browser.xul chrome://restclient/content/overlay.xul
overlay chrome://navigator/content/navigator.xul chrome://restclient/content/overlay.xul
style chrome://global/content/customizeToolbar.xul chrome://restclient/content/css/overlay.css
这告诉我们,在你的包中,唯一有效的内部 chrome:
URI将格式为 chrome:// restclient / content /
,并将引用根目录下的内容目录的加载项。
所以,我们现在寻找所有的 chrome:
上。为此, grep -nri chrome:*
的命令行是一种简单的方法。 grep
可作为多个操作系统下的标准实用程序使用。在Windows中,我通常会从获取。从这个命令我们得到:
chrome.manifest:4:overlay chrome://browser/content/browser.xul chrome: //restclient/content/overlay.xul
chrome.manifest:5:overlay chrome://navigator/content/navigator.xul chrome://restclient/content/overlay.xul
chrome.manifest: 6:style chrome://global/content/customizeToolbar.xul chrome://restclient/content/css/overlay.css
content / css / overlay.css:30:list-style-image:url( chrome://restclient/content/images/icon16.png)!important
content / css / overlay.css:33:list-style-image:url(chrome://restclient/content/images/icon16.png)!important;
content / js / restclient.js:51:i18nStrings = new restclient.StringBundle(chrome://restclient/locale/restclient.properties);
content / js / restclient.main.js:1040:xslDocument.load(chrome://restclient/content/xsl/XMLPrettyPrint.xsl);
content / js / restclient.main.js:1053:xslDoc.load(chrome://restclient/content/xsl/XMLIndent.xsl); * /
content / js / restclient.overlay .js:68:browser.selectedTab = browser.addTab(chrome://restclient/content/restclient.html);
content / overlay.xul:2:<?xml-stylesheet href =chrome://restclient/content/css/overlay.csstype =text / css?>
content / overlay.xul:7:< script type =application / x-javascriptsrc =chrome://restclient/content/js/restclient.js/>
content / overlay.xul:8:< script type =application / x-javascriptsrc =chrome://restclient/content/js/restclient.overlay.js/>
content / overlay.xul:23:image =chrome://restclient/content/images/icon16.png
content / overlay.xul:35:image =chrome:// restclient /内容/图片/ icon16.png
content / overlay.xul:46:image =chrome://restclient/content/images/icon16.png
content / overlay.xul:58:image =chrome://restclient/content/images/icon16.png/>
modules / StringBundle.js:59:* new StringBundle(chrome://example/locale/strings.properties);
现在,我们可以通过手动查看问题,但是我们可以缩短快速列出使用命令找到明显的问题: grep -nri chrome:* | grep -v chrome:// restclient / content /
。这将给我们任何 chrome:
URI,这些URI不是用于引用加载项的内容
的格式。获得的列表可以容易地包含引用附加文件外的文件的有效的 chrome:
URI。所以我们可能需要做更多的检查。从上面的命令我们得到:
content / js / restclient.js:51:i18nStrings = new restclient.StringBundle ://restclient/locale/restclient.properties);
modules / StringBundle.js:59:* new StringBundle(chrome://example/locale/strings.properties);
第一个是 locale
chrome:
URI。您不要在 chrome.manifest 中指定 locale
。因此,这是无效的。查看 content / js / restclient.js 的第51行,它是活动代码。当它实际使用时,它将无效。
第二种可能性是一个典型的例子 chrome:
URI。该行以 *
开头,暗示它可能是一个评论。检查 modules / StringBundle.js 的第59行显示它是一条注释。
下一步,如果尚未找到问题,将解决已知无效的 chrome:
URI并进行测试,看看是否解决了这个问题。在这种情况下,我们已经知道问题是什么,所以没有必要检查。
但是,鉴于 chrome:// restclient / locale / restclient.properties
无效,并且A)您的附件中没有这样的文件,B)没有 locale
在您的 chrome.manifest 这意味着如果该代码被执行,它将失败。基本上看来,函数 restclient.i18n
是死/坏代码,应该被删除。鉴于该功能是唯一使用 modules / StringBundle.js 文件,它也可以被删除。显然,如果这是你正在积极的工作,那就是一个不同的故事。
在这方面,我还注意到浏览器控制台中的其他几个错误你应该看看:
21:26:37.975 SyntaxError:test for equality(==)mistyped as assignment (=)?1 chrome://restclient/content/js/bootstrap.js:1557:33
21:26:37.989 TypeError:variable url redeclares argument1 chrome://restclient/content/js/restclient.main .js:376:8
虽然这些并不是固有的错误,但通常不需要任何东西在您的附加组件的正常操作期间,在浏览器控制台中显示。虽然,鉴于jquery.js中报告的各种错误还有几个?
I'm debugging a XUL-based Firefox extension which has been broken by Firefox 46 release.
When I run the extension, the Browser console shows:
Invalid chrome URI: /
with neither line numbers nor stack trace.
On Web forums, I've read that ChromeBug could be used for that. Then, I've tried the latest stable version of ChromeBug (1.7.2) but it hasn't been updated since oct. 2014, and seems to be incompatible with recent Firefox versions.
Because the extension is an "old-style" one, I cannot use the Add-on debugger, therefore I used the Browser toolbox, but it doesn't display the exception.
Considering the number of lines of the extension, wandering around in the code is not an option. Any idea how I could get a stack trace?
When getting this type of error in the Browser Console where you are given very little information as to what is causing the error it is likely that the error is not in JavaScript, and probably not even inside your code. In such cases, it is impossible to obtain a JavaScript stack trace because it just doesn't exist.
Such a thing is usually caused by issues in XUL or HTML used in a popup or tab that is opened. Your add-on opens a tab with the contents of chrome://restclient/content/restclient.html. Substituting for that file an HTML document with no content makes the error go away.
Using a binary search of the contents of that file (comment-out/delete progressive half portions of the file at a time and test to see if the errors still exist) to A) confirm that the error is there and B) what is causing the error, results in determining that the following line is causing the error to show up in the Browser Console (line 197):
<input class="span5" style="width:-moz-calc(100% - 1em) !important;" type="password" name="password" autocomplete="on" placeholder="Password">
A little more testing shows that the problem goes away when type
is not password
. Copying the original HTML document to a place where I can access it easily with a file:
URL, results in no such error in the browser console when the document is opened.
Thus, the conclusion is that it is a bug in Mozilla's code for <input type="password">
when loaded from a chrome:
URI.
Finding an invalid chrome:
URI in code without a stack trace:
If the problem was not found in the HTML or XUL files, it would be necessary to look through the chrome:
URIs which are used in your add-on to find what might be the cause.
chrome:
URIs have some properties we can take advantage of in tracking down such an issue:
chrome:
URIs are usually static.chrome:
URIs usually come in the formatchrome:\\packageName\{content,skin,locale}
- Your chrome.manifest file defines what
chrome:
URIs can be valid for your add-on/package. - Other chrome.manifest files define what
chrome:
URIs can be valid outside of your add-on/package.
So first look at your chrome.manifest file:
content restclient content/
resource restclient ./
overlay chrome://browser/content/browser.xul chrome://restclient/content/overlay.xul
overlay chrome://navigator/content/navigator.xul chrome://restclient/content/overlay.xul
style chrome://global/content/customizeToolbar.xul chrome://restclient/content/css/overlay.css
This tells us that in your package, the only valid internal chrome:
URIs will be in the format chrome://restclient/content/
and will refer to the content directory within the root directory of your add-on.
So, we now look for all the chrome:
URIs used in your add-on. To do that, the command line of grep -nri chrome: *
is an easy way to do so. grep
is available as a standard utility program under multiple operating systems. In Windows, I usually get it from Cygwin. From that command we get:
chrome.manifest:4:overlay chrome://browser/content/browser.xul chrome://restclient/content/overlay.xul
chrome.manifest:5:overlay chrome://navigator/content/navigator.xul chrome://restclient/content/overlay.xul
chrome.manifest:6:style chrome://global/content/customizeToolbar.xul chrome://restclient/content/css/overlay.css
content/css/overlay.css:30: list-style-image: url("chrome://restclient/content/images/icon16.png") !important;
content/css/overlay.css:33: list-style-image: url("chrome://restclient/content/images/icon16.png") !important;
content/js/restclient.js:51: i18nStrings = new restclient.StringBundle("chrome://restclient/locale/restclient.properties");
content/js/restclient.main.js:1040: xslDocument.load("chrome://restclient/content/xsl/XMLPrettyPrint.xsl");
content/js/restclient.main.js:1053: xslDoc.load("chrome://restclient/content/xsl/XMLIndent.xsl");*/
content/js/restclient.overlay.js:68: browser.selectedTab = browser.addTab("chrome://restclient/content/restclient.html");
content/overlay.xul:2:<?xml-stylesheet href="chrome://restclient/content/css/overlay.css" type="text/css"?>
content/overlay.xul:7: <script type="application/x-javascript" src="chrome://restclient/content/js/restclient.js" />
content/overlay.xul:8: <script type="application/x-javascript" src="chrome://restclient/content/js/restclient.overlay.js" />
content/overlay.xul:23: image="chrome://restclient/content/images/icon16.png"
content/overlay.xul:35: image="chrome://restclient/content/images/icon16.png"
content/overlay.xul:46: image="chrome://restclient/content/images/icon16.png"
content/overlay.xul:58: image="chrome://restclient/content/images/icon16.png"/>
modules/StringBundle.js:59: * new StringBundle("chrome://example/locale/strings.properties");
Now, we could, and probably should, look through that manually for problems, but we can shorten the list quickly to find obvious problems with the command: grep -nri chrome: * | grep -v chrome://restclient/content/
. This will give us any chrome:
URIs which are not in the format for references to your add-on's content
. The list obtained could easily contain valid chrome:
URIs that reference files outside of your add-on. So, we might need to do more checking. From the above command we get:
content/js/restclient.js:51: i18nStrings = new restclient.StringBundle("chrome://restclient/locale/restclient.properties");
modules/StringBundle.js:59: * new StringBundle("chrome://example/locale/strings.properties");
The first is a locale
chrome:
URI. You do not specify a locale
in your chrome.manifest. It is, therefore, certainly invalid. Looking at line 51 of content/js/restclient.js it is in active code. When it actually gets used, it will be invalid.
The second possibility is a typical example chrome:
URI. The line begins with a *
hinting that it might be a comment. Checking line 59 of modules/StringBundle.js shows that it is a comment.
The next step, if the problem had not already been found, would be to resolve the known invalid chrome:
URI(s) and test to see if that solved the problem. In this instance, we already know what the problem is, so there is no need to check.
However, given that the chrome://restclient/locale/restclient.properties
is invalid and A) there is no such file in your add-on and B) no locale
defined in your chrome.manifest it means that if that code was executed it would fail. Basically it appears that function, restclient.i18n
, is dead/bad code and should be removed. Given that function is the only use of the modules/StringBundle.js file, it could be removed also. Obviously, if this is something you are actively working on then that is a different story.
In working on this, I also noted a couple of other errors in the Browser Console which you should probably take a look at:
21:26:37.975 SyntaxError: test for equality (==) mistyped as assignment (=)?1 chrome://restclient/content/js/bootstrap.js:1557:33
21:26:37.989 TypeError: variable url redeclares argument1 chrome://restclient/content/js/restclient.main.js:376:8
While these are not inherently errors, it is generally desirable to not have anything show up in the Browser Console during the normal operation of your add-on. Although, given the various errors reported in jquery.js what are a couple more?
这篇关于如何获取“无效的chrome URI”的堆栈跟踪例外情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!