-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Resource Timing: encoded/decoded body size for SW responses #33283
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
service-workers/service-worker/resource-timing-bodySize.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<script src="/common/utils.js"></script> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/test-helpers.sub.js"></script> | ||
<script> | ||
|
||
function test_scenario(name) { | ||
promise_test(async (t) => { | ||
const uid = token(); | ||
const worker_url = `resources/fetch-response.js?uid=${uid}`; | ||
const scope = `resources/fetch-response.html?uid=${uid}`; | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `${scope}&path=${name}`; | ||
const registration = await service_worker_unregister_and_register(t, worker_url, scope); | ||
t.add_cleanup(() => registration.unregister()); | ||
t.add_cleanup(() => iframe.remove()); | ||
await wait_for_state(t, registration.installing, 'activated'); | ||
const waitForMessage = new Promise(resolve => window.addEventListener('message', ({data}) => resolve(data))); | ||
document.body.appendChild(iframe); | ||
const {buffer, entry} = await waitForMessage; | ||
assert_greater_than(buffer.byteLength, 0); | ||
assert_equals(entry.decodedBodySize, buffer.byteLength); | ||
assert_equals(entry.encodedBodySize, buffer.byteLength); | ||
}, `Constructed response body size: ${name}`); | ||
} | ||
|
||
['constructed', 'forward', 'stream'].forEach(test_scenario); | ||
|
||
</script> |
12 changes: 12 additions & 0 deletions
12
service-workers/service-worker/resources/fetch-response.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
|
||
<script> | ||
fetch(new URLSearchParams(location.search).get('path')).then(async response => { | ||
const buffer = await response.arrayBuffer(); | ||
parent.postMessage({ | ||
buffer, | ||
entry: performance.getEntriesByType('resource')[0].toJSON(), | ||
}, '*'); | ||
}); | ||
</script> |
32 changes: 32 additions & 0 deletions
32
service-workers/service-worker/resources/fetch-response.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
self.addEventListener('fetch', event => { | ||
const path = event.request.url.match(/\/(?<name>[^\/]+)$/); | ||
switch (path.groups.name) { | ||
case 'constructed': | ||
event.respondWith(new Response(new Uint8Array([1, 2, 3]))); | ||
break; | ||
case 'forward': | ||
event.respondWith(fetch('/common/text-plain.txt')); | ||
break; | ||
case 'stream': | ||
event.respondWith((async() => { | ||
const res = await fetch('/common/text-plain.txt'); | ||
const body = await res.body; | ||
const reader = await body.getReader(); | ||
const stream = new ReadableStream({ | ||
async start(controller) { | ||
while (true) { | ||
const {done, value} = await reader.read(); | ||
if (done) | ||
break; | ||
|
||
controller.enqueue(value); | ||
} | ||
controller.close(); | ||
reader.releaseLock(); | ||
} | ||
}); | ||
return new Response(stream); | ||
})()); | ||
break; | ||
} | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The multiple uses of data here are a bit confusing. Can you rename the "internal" data to buffer, or something similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done