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

extension: close the popup once the report has opened #5341

Merged
merged 2 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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: 1 addition & 1 deletion lighthouse-extension/app/src/lighthouse-ext-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ window.runLighthouseInExtension = function(options, categoryIDs) {
.then(runnerResult => {
// return enableOtherChromeExtensions(true).then(_ => {
const blobURL = window.createReportPageAsBlob(runnerResult, 'extension');
chrome.windows.create({url: blobURL});
return new Promise(resolve => chrome.windows.create({url: blobURL}, resolve));
// });
}).catch(err => {
// return enableOtherChromeExtensions(true).then(_ => {
Expand Down
21 changes: 15 additions & 6 deletions lighthouse-extension/app/src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,27 @@ function createOptionItem(text, id, isChecked) {
* @param {!Window} background Reference to the extension's background page.
* @param {{selectedCategories: !Object<boolean>, useDevTools: boolean}} settings
*/
function onGenerateReportButtonClick(background, settings) {
async function onGenerateReportButtonClick(background, settings) {
showRunningSubpage();

const feedbackEl = document.querySelector('.feedback');
feedbackEl.textContent = '';

const {selectedCategories, useDevTools} = settings;

background.runLighthouseInExtension({
restoreCleanState: true,
flags: {throttlingMethod: useDevTools ? 'devtools' : 'simulate'},
}, selectedCategories).catch(err => {
try {
await background.runLighthouseInExtension({
restoreCleanState: true,
flags: {throttlingMethod: useDevTools ? 'devtools' : 'simulate'},
}, selectedCategories);

// Close popup once report is opened in a new tab
window.close();
} catch (err) {
handleError(err);
}

function handleError(err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to make this a function? I'd say either spin off as it's own function or just nest in the catch{}

let message = err.message;
let includeReportLink = true;

Expand All @@ -151,7 +160,7 @@ function onGenerateReportButtonClick(background, settings) {

hideRunningSubpage();
background.console.error(err);
});
}
}

/**
Expand Down