1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-17 12:01:13 +02:00

add alternative to window.webkitRequestFileSystem

This commit is contained in:
Kushagra Gour
2017-11-19 01:35:24 +05:30
parent 51aac2e63b
commit d2458a7b8b
2 changed files with 30 additions and 17 deletions

View File

@@ -200,6 +200,7 @@
"escodegen": true, "escodegen": true,
"utils": true, "utils": true,
"Promise": true, "Promise": true,
"Inlet": true "Inlet": true,
"db": true
} }
} }

View File

@@ -994,7 +994,9 @@ globalConsoleContainerEl, externalLibrarySearchInput, keyboardShortcutsModal
if (!isForExport) { if (!isForExport) {
contents += contents +=
'<script src="' + '<script src="' +
chrome.extension.getURL('lib/screenlog.js') + (chrome.extension
? chrome.extension.getURL('lib/screenlog.js')
: `${location.origin}/lib/screenlog.js`) +
'"></script>'; '"></script>';
} }
@@ -1073,7 +1075,8 @@ globalConsoleContainerEl, externalLibrarySearchInput, keyboardShortcutsModal
} }
function createPreviewFile(html, css, js) { function createPreviewFile(html, css, js) {
var contents = getCompleteHtml(html, css); const shouldInlineJs = !window.webkitRequestFileSystem;
var contents = getCompleteHtml(html, css, shouldInlineJs ? js : '');
var blob = new Blob([contents], { type: 'text/plain;charset=UTF-8' }); var blob = new Blob([contents], { type: 'text/plain;charset=UTF-8' });
var blobjs = new Blob([js], { type: 'text/plain;charset=UTF-8' }); var blobjs = new Blob([js], { type: 'text/plain;charset=UTF-8' });
@@ -1083,21 +1086,30 @@ globalConsoleContainerEl, externalLibrarySearchInput, keyboardShortcutsModal
trackEvent.hasTrackedCode = true; trackEvent.hasTrackedCode = true;
} }
// we need to store user script in external JS file to prevent inline-script if (shouldInlineJs) {
// CSP from affecting it. frame.src = frame.src;
writeFile('script.js', blobjs, function() { setTimeout(() => {
writeFile('preview.html', blob, function() { frame.contentDocument.open();
var origin = chrome.i18n.getMessage() frame.contentDocument.write(contents);
? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}` frame.contentDocument.close();
: `${location.origin}`; }, 10);
var src = `filesystem:${origin}/temporary/preview.html`; } else {
if (scope.detachedWindow) { // we need to store user script in external JS file to prevent inline-script
scope.detachedWindow.postMessage(src, '*'); // CSP from affecting it.
} else { writeFile('script.js', blobjs, function() {
frame.src = src; writeFile('preview.html', blob, function() {
} var origin = chrome.i18n.getMessage()
? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}`
: `${location.origin}`;
var src = `filesystem:${origin}/temporary/preview.html`;
if (scope.detachedWindow) {
scope.detachedWindow.postMessage(src, '*');
} else {
frame.src = src;
}
});
}); });
}); }
} }
scope.setPreviewContent = function(isForced) { scope.setPreviewContent = function(isForced) {