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

Investigate setting Pyodide HTTP headers via a service worker #904

Draft
wants to merge 63 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
9cd2603
Create draft PR for #903
create-issue-branch[bot] Jan 24, 2024
aa09f15
Create draft PR for #936
create-issue-branch[bot] Feb 27, 2024
8814cae
default to pyodide and switch to skulpt if needed
loiswells97 Feb 27, 2024
1f0e5d0
attempt to parse imports in the runnerfactory
loiswells97 Feb 27, 2024
12bdce4
refactoring
loiswells97 Feb 28, 2024
f0ba6c3
tidying for linter
loiswells97 Feb 28, 2024
825961e
tidying to clarify approach in pr
loiswells97 Feb 28, 2024
e4354ed
refactoring to fix things
loiswells97 Feb 28, 2024
534871c
tidying
loiswells97 Feb 28, 2024
fb17e4d
tidying
loiswells97 Feb 29, 2024
7a3a74c
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Feb 29, 2024
e69126c
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Feb 29, 2024
edabb66
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Feb 29, 2024
2f7cf0b
Merge branch 'main' into issues/903-Investigate_setting_Pyodide_HTTP_…
loiswells97 Mar 8, 2024
d78b24a
registering a service worker
loiswells97 Mar 8, 2024
80ccb46
playing with worker registration
sra405 Mar 18, 2024
ff0587f
fixing shikm assets
loiswells97 Apr 4, 2024
73ae099
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Apr 4, 2024
beaad38
initial attempt at explaining incompatible modules
loiswells97 Apr 4, 2024
901cd1d
Fixing snapshot and skulptrunner tests
loiswells97 Apr 4, 2024
88ce726
fixing pyodiderunner tests
loiswells97 Apr 4, 2024
ea622af
fixing py5 imported mode
loiswells97 Apr 4, 2024
95b85ab
fixing cypress tests
loiswells97 Apr 4, 2024
ef868e0
updating snapshot
loiswells97 Apr 4, 2024
8eb4c86
trial service worker approaches
sra405 Apr 5, 2024
f9d8b67
fixing linting warning
loiswells97 Apr 5, 2024
610f6ad
updating changelog
loiswells97 Apr 5, 2024
e399def
fixing the input function
loiswells97 Apr 5, 2024
797a559
trying to fix cypress
loiswells97 Apr 5, 2024
691f9fb
patching pygal tooltip formatter
loiswells97 Apr 8, 2024
b1683fe
couple of regex patches to eliminate some edge cases
loiswells97 Apr 8, 2024
f76ea51
tidying
loiswells97 Apr 8, 2024
fdc914d
moving pyodiderunner back for now to avoid conflicts
loiswells97 Apr 8, 2024
52c4067
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Apr 8, 2024
1b82f42
tidying
loiswells97 Apr 8, 2024
68d85dc
changing and fixing tests
loiswells97 Apr 9, 2024
41594e6
fixing more tests
loiswells97 Apr 9, 2024
a571b06
fix mission zero tests
loiswells97 Apr 9, 2024
ce79754
testing pythonrunner switching which runner is active
loiswells97 Apr 9, 2024
70d1eea
updating snapshot
loiswells97 Apr 9, 2024
8ef6da7
Merge remote-tracking branch 'origin/main' into issues/903-Investigat…
sra405 Apr 9, 2024
e53a055
tweaking and testing skulpt and pyodide runner visibilities
loiswells97 Apr 9, 2024
868ab31
tweaking incompatibility error message explanation
loiswells97 Apr 9, 2024
d2fcfc3
fix one of the mission zero cypress tests
loiswells97 Apr 10, 2024
a73fcad
update error explanation copy
loiswells97 Apr 10, 2024
9ecb83b
fix(PyodideWorker): doesn't work in a web component context so alteri…
sra405 Apr 10, 2024
bdb30a1
switching turtle to skulpt and forcing skulpt if sense hat always ena…
loiswells97 Apr 10, 2024
5d43c1a
update error explanation to include turtle
loiswells97 Apr 10, 2024
8e8bdc9
updating snapshot
loiswells97 Apr 10, 2024
e45e8e3
switching mission zero cypress port
loiswells97 Apr 10, 2024
176c0c9
feat(WIP-PyodideRunner,-PyodideWorker-&-PyodideServiceWorker): invest…
sra405 Apr 17, 2024
ee3f8b9
fix linting issues causing build failures
sra405 Apr 19, 2024
6971faf
Merge branch 'main' into issues/903-Investigate_setting_Pyodide_HTTP_…
sra405 Apr 19, 2024
e4ae4fa
updated PyodideWorker import urls
sra405 Apr 19, 2024
fd83726
updated pyodiderunner PyodideServiceWorker url
sra405 Apr 19, 2024
01cb4f6
RunnerFactory - force PyodideRunner at all times
sra405 Apr 19, 2024
830a909
RunnerFactory - comment line that'll break the build
sra405 Apr 19, 2024
017a78b
PyodideRunner - revert service worker path
sra405 Apr 19, 2024
d9b38f3
Merge branch 'pyodide-migration' into issues/936-Spike_Investigate_us…
sra405 Apr 29, 2024
73981ea
Merge pull request #937 from RaspberryPiFoundation/issues/936-Spike_I…
sra405 May 31, 2024
410b3d2
Merge branch 'main' into pyodide-migration
sra405 May 31, 2024
800d114
Merge remote-tracking branch 'origin/pyodide-migration' into issues/9…
sra405 May 31, 2024
3c484c3
feat(pyodideworker): wip approaches to registering service worker wit…
sra405 May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed

- Remove unused `/embedded/projects/:identifier` route (#1013)
- Runner defaults to `pyodide` (#937)

### Fixed

Expand All @@ -28,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix initial value of `user` in `WebComponentLoader` (#1021)
- Make `authKey` in e2e web component spec more realistic (#1022)
- Remove unused `ComponentStore` (#1023)
- Dynamic switching between `pyodide` and `skulpt` based on user imports (#937)

## [0.23.0] - 2024-05-09

Expand Down
26 changes: 16 additions & 10 deletions cypress/e2e/missionZero-wc.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ it("loads the sense hat library", () => {
});

it("sets initial criteria correctly", () => {
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", "from sense_hat import SenseHat");
cy.get("editor-wc").shadow().find("div[class=cm-content]").invoke("text", "");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("#results").should(
"contain",
Expand Down Expand Up @@ -100,7 +97,10 @@ it("resets criteria correctly", () => {
);
cy.get("editor-wc").shadow().find(".btn--run").contains("Run").click();
cy.get("#results").should("contain", '"readPressure":true');
cy.get("editor-wc").shadow().find("div[class=cm-content]").invoke("text", "");
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", "from sense_hat import SenseHat");
cy.get("editor-wc").shadow().find(".btn--run").contains("Run").click();
cy.get("#results").should(
"contain",
Expand Down Expand Up @@ -139,7 +139,13 @@ it("picks up calls to input()", () => {
.find("div[class=cm-content]")
.invoke("text", "input()");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc").shadow().contains("Text output").click();
cy.get("editor-wc")
.shadow()
.find(
"div[class='pythonrunner-container skulptrunner skulptrunner--active']",
)
.contains("Text output")
.click();
cy.get("editor-wc")
.shadow()
.find("span[contenteditable=true]")
Expand Down Expand Up @@ -174,7 +180,7 @@ it("does not return null duration if no change in focus", () => {
.find("div[class=cm-content]")
.invoke(
"text",
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.send_message("a")',
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
);
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("#results").should("not.contain", '"duration":null');
Expand All @@ -186,7 +192,7 @@ it("does not return null duration if focus changed before code run", () => {
.find("div[class=cm-content]")
.invoke(
"text",
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.send_message("a")',
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
);
cy.window().blur();
cy.window().focus();
Expand All @@ -200,7 +206,7 @@ it("returns duration of null if focus is lost", () => {
.find("div[class=cm-content]")
.invoke(
"text",
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.send_message("a")',
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
);
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.window().blur();
Expand All @@ -214,7 +220,7 @@ it("does not return duration of null if code rerun after focus lost", () => {
.find("div[class=cm-content]")
.invoke(
"text",
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.send_message("a")',
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
);
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.window().blur();
Expand Down
15 changes: 15 additions & 0 deletions cypress/e2e/spec-wc.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ describe("default behaviour", () => {
cy.get("editor-wc").shadow().contains("Visual output").click();
cy.get("editor-wc").shadow().find("#root").should("not.contain", "yaw");
});

it("does not render astro pi component if sense hat unimported", () => {
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", "import sense_hat");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", "import p5");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc").shadow().contains("Visual output").click();
cy.get("editor-wc").shadow().find("#root").should("not.contain", "yaw");
});
});

describe("when load_remix_disabled is true, e.g. in editor-standalone", () => {
Expand Down
40 changes: 40 additions & 0 deletions public/PyodideServiceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
self.addEventListener("install", () => {
self.skipWaiting();
});

self.addEventListener("activate", (event) => {
event.waitUntil(self.clients.claim());
});

self.addEventListener("fetch", (event) => {
if (
event.request.cache === "only-if-cached" &&
event.request.mode !== "same-origin"
) {
return;
}

console.log(event.request);

const interceptedRequests = ["pyodide", "Pyodide"];

if (!interceptedRequests.some((str) => event.request.url.includes(str))) {
event.respondWith(
fetch(event.request)
.then((response) => {
console.log(`Intercepted: ${event.request.url}`);

const body = response.body;
const status = response.status;
const headers = new Headers(response.headers);
const statusText = response.statusText;

headers.set("Cross-Origin-Embedder-Policy", "require-corp");
headers.set("Cross-Origin-Opener-Policy", "same-origin");

// return new Response(body, { status, statusText, headers });
})
.catch(console.error),
);
}
});
Loading
Loading