Still can not import "local" files in webworker code
shlomil opened this issue · comments
It's strange, I tried with this code and got no error:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython.js"
crossorigin="anonymous">
</script>
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython_stdlib.js"
crossorigin="anonymous">
</script>
</head>
<body>
<script type="text/python" class="webworker" id="worker">
from browser import bind, self
from some_module import some_func
@bind(self, "message")
def message(evt):
result = 'pong' if evt.data == 'ping' else evt.data
workerResult = f'Result: {result}'
self.send(workerResult)
</script>
<script type="text/python">
from browser import worker
def ready(w):
print('ready')
w.send('ping')
def message(ev):
print(ev.data)
worker.create_worker("worker", onready=ready, onmessage=message)
</script>
</body>
</html>
The page is loaded by an http request, not by opening the local file.
The exact above code fails for me. This probably needs further investigation...
So more details:
If I change the script source to jsdeliver's brython 3.12.2 it doesn't fail.
I'm testing on my localhost using a python3 commandline single line webserver ... no https - might be related to some restrictions on webworkers? OTOH 3.12.2 still works fine.
chrome version: Version 122.0.6261.128 (Official Build) (64-bit)
Think of any other information that might be helpful?
*(yes, ofcourse it's not a local file, I should have written that it's simulating including "local file")
I have uploaded the page on the Brython site. It works for me, tested on Firefox, Chrome and Edge.
I have uploaded the page on the Brython site. It works for me, tested on Firefox, Chrome and Edge.
Ok, now this is becoming very strange:
- Going to the link above - Works
- I saved the page locally, created some_module.py (because it's not included in the page downloads), fired "python3 -m http.server 7777", try to access it - Fails with chrome, Fails with Firefox
- I copied the files to a domain with ssl, try to access it - Fails
(The domain is moslty protect by http auth but I hope I managed to disable it for these files so you can access it) - Tested on a different machine with Windows installed - same outcomes
So, a server configuration issue maybe?
and this is the same but with 3.12.2 that works on all cases
I think I got it, there was a bug when the html page is located at server root. Can you try with the latest version ?
Yes, indeed.
I can confirm that the latest version form git solved the issue on both my localhost and on remote.
Thank you very much :)