Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading script from dat url fails #24

Open
paul90 opened this issue Oct 12, 2018 · 6 comments
Open

Loading script from dat url fails #24

paul90 opened this issue Oct 12, 2018 · 6 comments

Comments

@paul90
Copy link

paul90 commented Oct 12, 2018

In a index.html scripts loaded from a dat url fail to load. For example

<script src='dat://federated-wiki-client.hashbase.io/client.js' type='text/javascript'></script>

fails to load with Loading failed for the <script> with source “dat://federated-wiki-client.hashbase.io/client.js”. in the browser console.

@paul90
Copy link
Author

paul90 commented Oct 12, 2018

Discovered while looking at using Content Security Policy to resolve the the CORS issue raised in #23

@paul90
Copy link
Author

paul90 commented Oct 12, 2018

The code in content_script.js

[...document.scripts]
.filter(e => e.src.startsWith('dat://'))
.forEach(e => {
// write a new script element with a http url
const scriptTag = document.createElement('script')
scriptTag.src = e.src.replace('dat://', 'http://');
e.parentNode.appendChild(scriptTag);
});

does not appear to being called. If I run it in the console it works, and the scripts are loaded.

This is with Firefox Dev. Edition 63.0b13 on macOS.

@sammacbeth
Copy link
Owner

This is a known issue - the protocol handler does not work for non-main-frame requests, so we try to re-write them in the content-script. However, doing this is prone to race conditions as you have to chase every script tag injected on the page and update it fast enough that it doesn't cause some other issue.

I'll have a new experimental version soon which will fix this class of issue as we will use a new protocol handler implementation from the libdweb project.

@raphaelbastide
Copy link

Is there some news regarding this issue and the experimental version with the new protocol?

@sammacbeth
Copy link
Owner

Is there some news regarding this issue and the experimental version with the new protocol?

Yes. It's dat-webext which bundles the whole dat stack inside the extension. Details on how it works are in this blog post.

Unfortunately, as it uses experimental APIs, it cannot be easily shipped to Firefox users at present, though Mozilla are looking into featuring dweb extensions like this on the AMO store, and permitting their use of experimental APIs. In the meantime, it can be tested on Desktop in Cliqz's Beta channel (a Firefox fork), or on Android in Cliqz Concept Browser.

@raphaelbastide
Copy link

@sammacbeth Thank you very much for that article and your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants