Is history.replaceState broken for XUL applications and plugins?

我们两清 提交于 2019-11-28 10:38:05

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/19093931/is-history-replacestate-broken-for-xul-applications-and-plugins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!