-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Stop the trace when multiple tabs are found. #639
Changes from 1 commit
2a9d09b
eb0d9a9
e21fd75
065d327
5d571f4
cc4b7b4
40919bb
5f7f0a6
acc3c4f
fcf2b0b
3b4379e
809c565
3d2d822
a6238f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…Attached
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,8 +216,9 @@ class Driver { | |
/** | ||
* Checks all serviceworkes and see if any duplications are running | ||
* @param {string} pageUrl | ||
* @return {Promise} | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a |
||
checkForMultipleServiceWorkers(pageUrl) { | ||
checkForMultipleTabsAttached(pageUrl) { | ||
// Get necessary information of serviceWorkers | ||
const getRegistrations = new Promise(resolve => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe pull this out into a |
||
this.once('ServiceWorker.workerRegistrationUpdated', resolve); | ||
|
@@ -239,9 +240,8 @@ class Driver { | |
}); | ||
|
||
if (activeServiceWorkers.length > 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to do something slightly different. So far we have all worker versions that are attached to the registration that matches on the scopeURL. Perf. That's what we need... so far. Our versions look like this: https://chromedevtools.github.io/debugger-protocol-viewer/tot/ServiceWorker/#type-ServiceWorkerVersion We need all controlledClients of all if |
||
const activeSW = activeServiceWorkers[0].scriptURL; | ||
throw new Error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'll need to call Also, Is there any other cleanup we need to do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will check if anything else needs to be done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only needed to disconnect the driver. Couldn't find anything else. I will have a look at what happens when we close the trace in between.. (shouldn't be part of this PR) |
||
`Unable to kill ServiceWorker(${activeSW}).` | ||
'You probably have multiple tabs open.' | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,7 @@ const path = require('path'); | |
* i. beginEmulation | ||
* ii. cleanAndDisableBrowserCaches | ||
* iii. clearDataForOrigin | ||
* iiii. checkForMultipleServiceWorkers | ||
* iiiii. forceUpdateServiceWorkers | ||
* iiii. checkForMultipleTabsAttached | ||
* | ||
* 2. For each pass in the config: | ||
* A. GatherRunner.beforePass() | ||
|
@@ -94,6 +93,9 @@ class GatherRunner { | |
}).then(_ => { | ||
// Clears storage for origin. | ||
return driver.clearDataForOrigin(options.url); | ||
}).then(_ => { | ||
// Check Service Workers running | ||
return driver.checkForMultipleTabsAttached(options.url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like |
||
}); | ||
} | ||
|
||
|
@@ -221,7 +223,7 @@ class GatherRunner { | |
return driver.connect() | ||
.then(_ => { | ||
// Check Service Workers running | ||
return driver.checkForMultipleServiceWorkers(options.url); | ||
return driver.checkForMultipleTabsAttached(options.url); | ||
}) | ||
.then(_ => GatherRunner.setupDriver(driver, options)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,8 +63,8 @@ module.exports = function(url, flags, configJSON) { | |
// kick off a lighthouse run | ||
resolve(Runner.run(driver, {url, flags, config})); | ||
})).catch(err => { | ||
if (err.message.toLowerCase().startsWith('unable to kill')) { | ||
log.error('Multiple tabs', err.message); | ||
if (err.message.toLowerCase().includes('multiple tabs')) { | ||
log.error('status', err.message); | ||
return Promise.reject(''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not clear why we reject upwards with an empty message in this case, but I think I'm missing something.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reason why is not to throw a runtime error... (#639 (comment)) and wanted to show a better error message so i do it in the catch but perhaps i need to do it in the lighthouse-cli instead? (while writing i think that's a better option) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulirish this one i still need to fix (forgot about this one) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All good. |
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,14 +101,11 @@ describe('Browser Driver', () => { | |
} | ||
}); | ||
|
||
const errorMsg = `Unable to kill ServiceWorker(${swUrl}).`; | ||
return driverStub.checkForMultipleServiceWorkers(pageUrl) | ||
.catch(err => { | ||
assert.equal(err.message, errorMsg); | ||
}); | ||
return driverStub.checkForMultipleTabsAttached(pageUrl) | ||
.then(_ => assert.ok(false), _ => assert.ok(true)); | ||
}); | ||
|
||
it('will will succeed when old sw are deleted', () => { | ||
it('will succeed when old sw are deleted', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this test still what you want given what @paulirish said about deleted service workers? |
||
const pageUrl = 'https://example.com/'; | ||
const swUrl = `${pageUrl}sw.js`; | ||
const registrations = [1, 2].map(i => | ||
|
@@ -125,11 +122,11 @@ describe('Browser Driver', () => { | |
} | ||
}); | ||
|
||
const errorMsg = new RegExp(`Unable to kill ServiceWorker(${swUrl}).`); | ||
assert.doesNotThrow(() => driverStub.checkForMultipleServiceWorkers(pageUrl), errorMsg); | ||
return driverStub.checkForMultipleTabsAttached(pageUrl) | ||
.then(_ => assert.ok(true), _ => assert.ok(false)); | ||
}); | ||
|
||
it('will will succeed when only one sw loaded', () => { | ||
it('will succeed when only one sw loaded', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/sw/service worker |
||
const pageUrl = 'https://example.com/'; | ||
const swUrl = `${pageUrl}sw.js`; | ||
const registrations = [createSWRegistration(1, pageUrl)]; | ||
|
@@ -144,8 +141,8 @@ describe('Browser Driver', () => { | |
} | ||
}); | ||
|
||
const errorMsg = new RegExp(`Unable to kill ServiceWorker(${swUrl}).`); | ||
assert.doesNotThrow(() => driverStub.checkForMultipleServiceWorkers(pageUrl), errorMsg); | ||
return driverStub.checkForMultipleTabsAttached(pageUrl) | ||
.then(_ => assert.ok(true), _ => assert.ok(false)); | ||
}); | ||
}); | ||
|
||
|
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.
service workers