Skip to content

Commit

Permalink
Introduce <script type=webbundle>
Browse files Browse the repository at this point in the history
Introduce <script>-based API for subresource loading with Web Bundles.

See the design doc [1] for the motivation of switching from
<link>-based API to <script>-based API. The explainer [2] was already
updated to use <script>-based API.

This feature is guarded by `SubresourceWebBundles` flag.

We eventually drop the <link rel=webbundle> support and remove the
<link>-based API code once we can confirm <script>-based API can be
used as a replacement of <link>-based API.

This CL should be considered as the first step to switch to
<script>-based API. There are still gaps between <link>-based API and
<script>-based API, which will be addressed later [3].

This CL intentionally adds a very minimum test for <script
type=webbundle>. Tests will be added in follow-up CLs. The plan is:

1. We will convert the existing tests incrementally, replacing
   <link>-based API with new <script>-based API. For example, for WPT,
   we will convert:

   from: wpt/web-bundle/subresource-loading/link-*.html
   to: wpt/web-bundle/subresource-loading/script-.html

2. If we find an issue of the implementation or find a missing feature
   by rewriting a test, we'll fix or update our implementation.

3. Continue until we can convert all existing tests.

4. Once we finish converting all tests, we can switch to
   <script>-based API and be ready to drop <link>-based API.

We'll also add tests which are specific to <script>-based API as
necessary. These efforts should be tracked by crbug.com/1245166.

[1]: https://docs.google.com/document/d/1q_SodTcLuwya4cXt1gIRaVrkiaBfwWyPvkY1fqRKkgM/edit?usp=sharing&resourcekey=0-dqrFOGVCYsg8WRZ4RFgwuw
[2]: https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md
[3]: WICG/webpackage#670

Bug: 1245166
Change-Id: I5109b6e692baf10fd1d8a31a31d93176d4dc4ad2
  • Loading branch information
hayatoito authored and chromium-wpt-export-bot committed Oct 4, 2021
1 parent a21ad2a commit b5d7720
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
44 changes: 44 additions & 0 deletions web-bundle/subresource-loading/script-replace.https.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<title>Subresource loading with script-based API</title>
<link
rel="help"
href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md"
/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script id="old_script" type="webbundle">
{
"source": "../resources/wbn/subresource.wbn",
"resources": ["../resources/wbn/root.js", "../resources/wbn/old-wbn.js"]
}
</script>
<script>
promise_test(async () => {
const old_script = document.querySelector("#old_script");

assert_true((await fetch(
"https://web-platform.test:8444/web-bundle/resources/wbn/root.js"
)).ok);
assert_false((await fetch(
"https://web-platform.test:8444/web-bundle/resources/wbn/submodule.js"
)).ok);

const new_script = document.createElement("script");
new_script.type = "webbundle";
new_script.textContent = JSON.stringify({
source: "../resources/wbn/subresource.wbn",
resources: ["../resources/wbn/submodule.js", "../resources/wbn/new-wbn.js"],
});

old_script.replaceWith(new_script);

assert_false((await fetch(
"https://web-platform.test:8444/web-bundle/resources/wbn/root.js"
)).ok);
assert_true((await fetch(
"https://web-platform.test:8444/web-bundle/resources/wbn/submodule.js"
)).ok);
}, "Subresource should be loaded from webbundle");
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>Subresource loading with script-based API</title>
<link rel="help" href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script type="webbundle">
{
"source": "../resources/wbn/subresource.wbn",
"resources": ["../resources/wbn/root.js"]
}
</script>
<script>
promise_test(async () => {
const response = await fetch('https://web-platform.test:8444/web-bundle/resources/wbn/root.js');
assert_true(response.ok);
}, "Subresource should be loaded from webbundle");
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<DOCTYPE html>
<html>
<title>HTMLScriptElement.supports webbundle</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
assert_true(HTMLScriptElement.supports('webbundle'));
}, 'HTMLScriptElement.supports returns true for \'webbundle\'');

test(() => {
assert_false(HTMLScriptElement.supports(' webbundle'));
assert_false(HTMLScriptElement.supports('webbundle '));
}, 'HTMLScriptElement.supports returns false for unsupported types');
</script>

0 comments on commit b5d7720

Please sign in to comment.