Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2c267c

Browse files
committed
cherry-pick(#37689): Revert "fix(trace): should survive ping as the first command after restart"
1 parentd1fdd81 commitd2c267c

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

‎packages/trace-viewer/src/sw/main.ts‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,16 @@ async function doFetch(event: FetchEvent): Promise<Response> {
9393
constrequest=event.request;
9494
constclient=awaitself.clients.get(event.clientId);
9595

96-
consturlInScope=request.url.startsWith(self.registration.scope) ?newURL(unwrapPopoutUrl(request.url)) :undefined;
97-
constrelativePath=urlInScope?.pathname.substring(scopePath.length-1);
98-
99-
if(relativePath!=='/contexts'&&!clientIdToTraceUrls.has(event.clientId)){
100-
// Service worker was restarted upon subresource fetch.
101-
// It was stopped because ping did not keep it alive since the tab itself was throttled.
102-
constparams=awaitloadClientIdParams(event.clientId);
103-
if(params){
104-
for(consttraceUrlofparams.traceUrls)
105-
awaitloadTrace(traceUrl,null,client,params.limit,()=>{});
106-
}
107-
}
108-
10996
// When trace viewer is deployed over https, we will force upgrade
11097
// insecure http subresources to https. Otherwise, these will fail
11198
// to load inside our https snapshots.
11299
// In this case, we also match http resources from the archive by
113100
// the https urls.
114101
constisDeployedAsHttps=self.registration.scope.startsWith('https://');
115102

116-
if(urlInScope&&relativePath){
103+
if(request.url.startsWith(self.registration.scope)){
104+
consturl=newURL(unwrapPopoutUrl(request.url));
105+
constrelativePath=url.pathname.substring(scopePath.length-1);
117106
if(relativePath==='/ping'){
118107
awaitgc();
119108
returnnewResponse(null,{status:200});
@@ -123,12 +112,12 @@ async function doFetch(event: FetchEvent): Promise<Response> {
123112
returnnewResponse(null,{status:200});
124113
}
125114

126-
consttraceUrl=urlInScope.searchParams.get('trace');
115+
consttraceUrl=url.searchParams.get('trace');
127116

128117
if(relativePath==='/contexts'){
129118
try{
130-
constlimit=urlInScope.searchParams.has('limit') ?+urlInScope.searchParams.get('limit')! :undefined;
131-
consttraceModel=awaitloadTrace(traceUrl!,urlInScope.searchParams.get('traceFileName'),client,limit,(done:number,total:number)=>{
119+
constlimit=url.searchParams.has('limit') ?+url.searchParams.get('limit')! :undefined;
120+
consttraceModel=awaitloadTrace(traceUrl!,url.searchParams.get('traceFileName'),client,limit,(done:number,total:number)=>{
132121
client.postMessage({method:'progress',params:{ done, total}});
133122
});
134123
returnnewResponse(JSON.stringify(traceModel!.contextEntries),{
@@ -143,20 +132,30 @@ async function doFetch(event: FetchEvent): Promise<Response> {
143132
}
144133
}
145134

135+
if(!clientIdToTraceUrls.has(event.clientId)){
136+
// Service worker was restarted upon subresource fetch.
137+
// It was stopped because ping did not keep it alive since the tab itself was throttled.
138+
constparams=awaitloadClientIdParams(event.clientId);
139+
if(params){
140+
for(consttraceUrlofparams.traceUrls)
141+
awaitloadTrace(traceUrl,null,client,params.limit,()=>{});
142+
}
143+
}
144+
146145
if(relativePath.startsWith('/snapshotInfo/')){
147146
const{ snapshotServer}=loadedTraces.get(traceUrl!)||{};
148147
if(!snapshotServer)
149148
returnnewResponse(null,{status:404});
150149
constpageOrFrameId=relativePath.substring('/snapshotInfo/'.length);
151-
returnsnapshotServer.serveSnapshotInfo(pageOrFrameId,urlInScope.searchParams);
150+
returnsnapshotServer.serveSnapshotInfo(pageOrFrameId,url.searchParams);
152151
}
153152

154153
if(relativePath.startsWith('/snapshot/')){
155154
const{ snapshotServer}=loadedTraces.get(traceUrl!)||{};
156155
if(!snapshotServer)
157156
returnnewResponse(null,{status:404});
158157
constpageOrFrameId=relativePath.substring('/snapshot/'.length);
159-
constresponse=snapshotServer.serveSnapshot(pageOrFrameId,urlInScope.searchParams,urlInScope.href);
158+
constresponse=snapshotServer.serveSnapshot(pageOrFrameId,url.searchParams,url.href);
160159
if(isDeployedAsHttps)
161160
response.headers.set('Content-Security-Policy','upgrade-insecure-requests');
162161
returnresponse;
@@ -167,7 +166,7 @@ async function doFetch(event: FetchEvent): Promise<Response> {
167166
if(!snapshotServer)
168167
returnnewResponse(null,{status:404});
169168
constpageOrFrameId=relativePath.substring('/closest-screenshot/'.length);
170-
returnsnapshotServer.serveClosestScreenshot(pageOrFrameId,urlInScope.searchParams);
169+
returnsnapshotServer.serveClosestScreenshot(pageOrFrameId,url.searchParams);
171170
}
172171

173172
if(relativePath.startsWith('/sha1/')){
@@ -176,13 +175,13 @@ async function doFetch(event: FetchEvent): Promise<Response> {
176175
for(consttraceofloadedTraces.values()){
177176
constblob=awaittrace.traceModel.resourceForSha1(sha1);
178177
if(blob)
179-
returnnewResponse(blob,{status:200,headers:downloadHeaders(urlInScope.searchParams)});
178+
returnnewResponse(blob,{status:200,headers:downloadHeaders(url.searchParams)});
180179
}
181180
returnnewResponse(null,{status:404});
182181
}
183182

184183
if(relativePath.startsWith('/file/')){
185-
constpath=urlInScope.searchParams.get('path')!;
184+
constpath=url.searchParams.get('path')!;
186185
consttraceViewerServer=clientIdToTraceUrls.get(event.clientId??'')?.traceViewerServer;
187186
if(!traceViewerServer)
188187
thrownewError('client is not initialized');

‎tests/library/trace-viewer.spec.ts‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,23 +2056,3 @@ test('should survive service worker restart', async ({ page, runAndTrace, server
20562056
constsnapshot2=awaittraceViewer.snapshotFrame('Set content');
20572057
awaitexpect(snapshot2.locator('body')).toHaveText('Old world');
20582058
});
2059-
2060-
test('should survive ping after service worker restart',async({ page, runAndTrace, server})=>{
2061-
consttraceViewer=awaitrunAndTrace(async()=>{
2062-
awaitpage.goto(server.EMPTY_PAGE);
2063-
awaitpage.setContent('Old world');
2064-
awaitpage.evaluate(()=>document.body.textContent='New world');
2065-
});
2066-
constsnapshot1=awaittraceViewer.snapshotFrame('Evaluate');
2067-
awaitexpect(snapshot1.locator('body')).toHaveText('New world');
2068-
2069-
conststatus=awaittraceViewer.page.evaluate(async()=>{
2070-
constresponse1=awaitfetch('restartServiceWorker');
2071-
constresponse2=awaitfetch('ping');
2072-
returnresponse1.status+'/'+response2.status;
2073-
});
2074-
expect(status).toBe('200/200');
2075-
2076-
constsnapshot2=awaittraceViewer.snapshotFrame('Set content');
2077-
awaitexpect(snapshot2.locator('body')).toHaveText('Old world');
2078-
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp