Skip to content

Commit

Permalink
createTab: use async so error messages are better surfaced
Browse files Browse the repository at this point in the history
This helped me see that incognito was not enabled when debugging with Firefox.
  • Loading branch information
philc committed Sep 17, 2023
1 parent f8d5627 commit b2c53be
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,23 @@ const moveTab = function ({ count, tab, registryEntry }) {
});
};

// TODO(philc): Rename to createRepeatCommand.
const mkRepeatCommand = (command) => (function (request) {
request.count--;
if (request.count >= 0) {
// TODO(philc): I think we can remove this return statement, and all returns
// from commands built using mkRepeatCommand.
return command(request, (request) => (mkRepeatCommand(command))(request));
}
});

// These are commands which are bound to keystrokes which must be handled by the background page.
// They are mapped in commands.coffee.
const BackgroundCommands = {
// Create a new tab. Also, with:
// Create a new tab. Also, with:
// map X createTab http://www.bbc.com/news
// create a new tab with the given URL.
createTab: mkRepeatCommand(function (request, callback) {
createTab: mkRepeatCommand(async function (request, callback) {
if (request.urls == null) {
if (request.url) {
// If the request contains a URL, then use it.
Expand All @@ -187,13 +190,13 @@ const BackgroundCommands = {
}
}
}

if (request.registryEntry.options.incognito || request.registryEntry.options.window) {
const windowConfig = {
url: request.urls,
incognito: request.registryEntry.options.incognito || false,
};
return chrome.windows.create(windowConfig, () => callback(request));
const result = await chrome.windows.create(windowConfig);
callback(request);
} else {
let openNextUrl;
const urls = request.urls.slice().reverse();
Expand Down

0 comments on commit b2c53be

Please sign in to comment.