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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…