I am using Google Closure and and I am trying to make a Chrome packaged app.
My call to goog.require
causes an error:
Uncaught document.write() is not available in packaged apps.
The culprit is in base.js
goog.writeScriptTag_ = function(src) {
if (goog.inHtmlDocument_()) {
var doc = goog.global.document;
// If the user tries to require a new symbol after document load,
// something has gone terribly wrong. Doing a document.write would
// wipe out the page.
if (doc.readyState == 'complete') {
// Certain test frameworks load base.js multiple times, which tries
// to write deps.js each time. If that happens, just fail silently.
// These frameworks wipe the page between each load of base.js, so this
// is OK.
var isDeps = /\bdeps.js$/.test(src);
if (isDeps) {
return false;
} else {
throw Error('Cannot write "' + src + '" after document load');
}
}
doc.write(
'<script type="text/javascript" src="' + src + '"></' + 'script>');
return true;
} else {
return false;
}
};
Is Google Closure incompatible with Google Chrome packaged apps? Closure has so many benefits for large Javascript projects it is really hard to give up such a valuable tool.
EDIT: I know that if the Closure Compiler is used in addition to the Closure libraries, there is no goog.require, but that clearly makes development and debugging much more difficult.