XUL 应用程序和插件的 history.replaceState 是否已损坏? [英] Is history.replaceState broken for XUL applications and plugins?

查看:27
本文介绍了XUL 应用程序和插件的 history.replaceState 是否已损坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 XUL 应用程序中有一个浏览器对象,如下所示:

<?xml-stylesheet href="chrome://global/skin" type="text/css"?><窗口标题="学生"xmlns:html="http://www.w3.org/1999/xhtml"xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"宽度=800像素"高度=500像素"><groupbox flex="1"><caption label="学生"/><浏览器类型="chrome" src="chrome://myapp/content/index.html" flex="1"/></groupbox></窗口>

index.html 是:

<头><title>学生页面</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><身体><h1>history.replaceState</h1>出了点问题<脚本>尝试{history.replaceState(null, '', 'chrome://myapp/content/another.html');}catch(e){//不确定如何在不创建辅助函数的情况下在 XUL 中记录内容警报(e);}</html>

打开错误:

<块引用>

[异常...组件返回失败代码:0x80004005(NS_ERROR_FAILURE) [nsIDOMHistory.replaceState]" nsresult:0x80004005(NS_ERROR_FAILURE)"位置:JS框架::chrome://myapp/content/index.html :: :: line 11" 数据:没有]

我试图在浏览器元素中使用 Angularjs,但由于它依赖 history.replaceState 做它应该做的事情,所以它在 XUL 应用程序中失败了.

[更新]

将浏览器元素的类型设置为 content-primary 时,location.replaceState 不会抛出异常.

 

[更新]

XMLHttpRequest 问题状态返回 0 并且 Angular 检查 if(status... 在 Firefox 中,当从磁盘打开文件时,它仍会返回状态 200,但不会在 XUL 中返回.这会导致模板无法加载.>

将角度源中 isSuccess 中的返回值更改为 return (200 <= status && status < 300)||status===0; 现在加载模板.>

[更新]

当我点击一个链接时,我看到像 #/students/22 这样的链接变成了 unsafe:chrome://myapp/content/index.html#/students/22 以警告告终,告诉我 unsafe 不是注册协议,这不是 XUL 问题.要将 chrome://协议添加为 Angular 中的可信协议,我在 application.js 中执行了以下操作:

angular.module('student', []).config(['$routeProvider','$compileProvider',函数($routeProvider,$compileProvider){$compileProvider.urlSanitizationWhitelist(/^\s*(chrome|file):/);

现在它只会打开指向 chrome://path/filefile://path/file

的链接

解决方案

browser 元素的类型设置为 content-primary 似乎修复了 location.replaceState 错误.

I have a browser object in my XUL application like so:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>

<window title="Students"
        xmlns:html="http://www.w3.org/1999/xhtml"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        width="800px"
        height="500px">
<groupbox flex="1">
  <caption label="Students"/>
  <browser type="chrome" src="chrome://myapp/content/index.html" flex="1"/>
</groupbox>   
</window>

And the index.html is:

<!DOCTYPE html>
<html>
  <head>
    <title>Student page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <h1>Something wrong with history.replaceState</h1>
    <script>
      try{
        history.replaceState(null, '', 'chrome://myapp/content/another.html');
      }catch(e){
        //not sure how to log stuff in XUL without creating helper functions
        alert(e);
      }
    </script>
  </body>
</html>

Opens up with an error:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHistory.replaceState]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://myapp/content/index.html :: :: line 11" data: no]

I was trying to use Angularjs in the browser element but since it's relying on history.replaceState doing what it's supposed to do it fails in a XUL application.

[update]

when setting type of the browser element to content-primary the location.replaceState does not throw an exception.

  <browser type="content-primary"
    src="chrome://myapp/content/index.html" flex="1"/>

[update]

XMLHttpRequest problem Status is returning 0 and Angular checks for if(status... In Firefox when opening the file from disk it would still return status 200 but not in XUL. This causes the templates not to load.

Changing the return in isSuccess in angular source to return (200 <= status && status < 300)||status===0; now loads the template.

[update]

When clicking a link I see that a link like #/students/22 becomes unsafe:chrome://myapp/content/index.html#/students/22 ending up in an alert telling me that unsafe is not a registered protocol this isn't a XUL issue. To add the chrome:// protocol as trusted in Angular I've done the following in my application.js:

angular.module('student', []).
  config(['$routeProvider','$compileProvider', 
    function($routeProvider,$compileProvider) {
      $compileProvider.urlSanitizationWhitelist(/^\s*(chrome|file):/);

Now it will only open links to chrome://path/file or file://path/file

解决方案

Setting type of the browser element to content-primary seems to fix the location.replaceState error.

这篇关于XUL 应用程序和插件的 history.replaceState 是否已损坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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