--- a/default.tmpl +++ b/default.tmpl @@ -62,7 +62,8 @@ import embed - platform.document.body.style.background = "#7f7f7f" + # FredyGames: black around the game, like the game's own background + platform.document.body.style.background = "#000" import pygame @@ -230,6 +231,30 @@ +// FredyGames: the pygbag runtime (pythons.js, CPython, the pygame-ce wheel and the package index) +// is served from the pgw/ folder next to this page, never from pygame-web.github.io. The package +// index and some built-in modules still name the original addresses, so every fetch() and +// XMLHttpRequest to them is redirected here; anything else from another origin is refused by the +// Content-Security-Policy below. +(() => { + const local = new URL("pgw/", document.baseURI).href + const remotes = ["https://pygame-web.github.io/archives/", location.origin + "/archives/"] + const fix = (url) => { + const s = String(url) + for (const r of remotes) + if (s.startsWith(r)) return local + s.slice(r.length) + return url + } + const nativeFetch = window.fetch + window.fetch = (input, init) => nativeFetch.call(window, + input instanceof Request ? (fix(input.url) === input.url ? input : new Request(fix(input.url), input)) : fix(input), + init) + const nativeOpen = XMLHttpRequest.prototype.open + XMLHttpRequest.prototype.open = function (method, url, ...rest) { + return nativeOpen.call(this, method, fix(url), ...rest) + } +})() + // this dict is available under PyConfig.config from __main__ config = { @@ -241,7 +266,8 @@ can_close : {{cookiecutter.can_close}}, archive : "{{cookiecutter.archive}}", gui_debug : 3, - cdn : "{{cookiecutter.cdn}}", + // FredyGames: absolute URL of the runtime copy inside this folder (vtx.js imports from it) + cdn : new URL("{{cookiecutter.cdn}}", document.baseURI).href, autorun : {{cookiecutter.autorun}}, PYBUILD : "{{cookiecutter.PYBUILD}}" } @@ -250,13 +276,13 @@