question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to externally load script via src=""

See original GitHub issue

For some reason, I get this brython.js:5183 Access to XMLHttpRequest at '../basichow/test.py?1572494543087' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. This occurs when I added the src="test.py" to the <script type="text/python"></script> Using Chrome and Brython.js version 8. The files are here. basichow.zip Any help be appreciated, thanks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
PierreQuentelcommented, Oct 31, 2019

This is already possible with Brython packages. If you run python -m brython --make_package test in the application directory, it generates the Javascript program test.brython.js that you can load with

<script src="test.brython.js"></script>

and then execute the code in main.py by

<script type="text/python">
import main
</script>

In this case there is no Ajax call, so the page will work with the file protocol. You can transfer the application files to a mobile phone and open the page, it will work 😃

1reaction
PierreQuentelcommented, Oct 31, 2019

You have probably modified test.py with something like

open("data here.txt")

The Python function open() is also implemented in Brython with an Ajax call (browsers don’t have access to the computer file system). The call is blocking (ie not asynchronous) because the Python function is also blocking; this causes the deprecation message, but you can ignore it (cf. the Brython FAQ for more information). And the call fails anyway because the protocol is file.

For the moment there is no real solution to this problem (you could put the file content inside a string in a Python script and import it, but that’s ugly…). I will try to find something better, I will keep you informed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - External file script is not loading - Stack Overflow
Check your relative path to the utility.js file and make sure to load juery.js library before load utility.js file. and finally try this,...
Read more >
How to Load External JavaScript Files From the Browser ...
This article will explain how you can load an external JavaScript file directly from the browser's console window as part of your prototyping ......
Read more >
How to tell if a <script> tag failed to load? - GeeksforGeeks
The problem is to identify whether the passed script loaded successfully or not using JavaScript. There are two methods which are discussed ...
Read more >
4. Loading Scripts Without Blocking - Even Faster Web Sites ...
The SRC attribute specifies the URL of the external file that needs to be loaded. The browser reads the script file from the...
Read more >
Using External JavaScript Libraries | Lightning Aura ...
The framework's content security policy mandates that external JavaScript libraries must be uploaded to Salesforce static resources.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found