Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Gracefully handle toolbar button mashing #3222

Closed
wants to merge 2 commits into from

Conversation

jaredhirsch
Copy link
Member

This patch consistently fixes #3097 for me. Two parts:

  1. When loading selector code into a page, manually concatenate all scripts, then kick off 1 browser.tabs.executeScript request. The old approach kicked off N executeScript promises sequentially, one for each script.

  2. Double-check the list of already-loading tabs just before starting to load code into a tab. Although this check is done elsewhere already, adding a check at the moment of truth seems to fix the remaining few weird timing bugs that lead to 'haywire' notifications.

Copy link
Contributor

@ianb ianb left a comment

Choose a reason for hiding this comment

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

I think we need to discuss this some – as it is I'm worried about losing visibility into our code through the concatenation.

});
return lastPromise.then(() => {
return Promise.all(filePromises).then(fileContents => {
let allScripts = fileContents.reduce((concatted, script) => { return concatted + ' ; ' + script });
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't this be fileContents.join("; ") ?

Copy link
Contributor

Choose a reason for hiding this comment

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

One bummer here is that we no longer get filenames or line positions. This is going to make debugging and Sentry much harder to work with.

I guess we could do a sourcemap? Though if we do, then using something like browserify (and doing this all as a make step) might be advantageous. I did a quick lookup of the sourcemap format, since maybe for pure concatenation it isn't that hard, but it looks pretty complicated. Though maybe it's not that complicated, since it looks like something like {offset: {line: 10}, map: {file: "aScript.js"}}} might work?

@@ -64,6 +64,11 @@ this.selectorLoader = (function() {
let loadingTabs = new Set();

exports.loadModules = function(tabId, hasSeenOnboarding) {
// Sometimes loadModules is called when the tab is already loading.
// Adding a check here seems to help avoid catastrophe.
if (loadingTabs.has(tabId)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this get in the way of loading modules on the same tab, when it's a new page? E.g., just reload the page and try to re-invoke screenshots, and then this check will stop it from loading...?

@@ -80,21 +85,43 @@ this.selectorLoader = (function() {
});
};

function readFile(path) {
return fetch(path, { mode: 'same-origin' }).then((response) => {
return response.blob();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be response.text() instead of response.blob(), skipping the FileReader stuff?

@ianb
Copy link
Contributor

ianb commented Jul 27, 2017

After discussion, some options to explore:

  1. Generate the sourcemap as part of the concatenation, generating them manually (appending the sourcemap as a data URL)
  2. Create a build step that concatenates files, maybe using concat-with-sourcemaps
  3. Create a build step that uses browserify, hacking our primitive module system to work with browserify
  4. Create a build step that uses browserify, and update our module system to use CommonJS modules (i.e., require, exports)

If we want to make minimal logic changes, then we should build two files, one that includes slides.js/etc, and one that does not. Right now slides.js (onboarding) runs based on whether the files are included. For the last option (where we use browserify properly) we probably have to change how onboarding is invoked. Maybe we can just use a query string on the script name?

@jaredhirsch
Copy link
Member Author

I'm now thinking this is the wrong approach. Closing

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple errors are thrown while opening and closing Firefox Screenshots
2 participants