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

Added CSP executeScript fallback #80

Merged
merged 10 commits into from
Jul 15, 2022
Merged

Added CSP executeScript fallback #80

merged 10 commits into from
Jul 15, 2022

Conversation

exdis
Copy link
Member

@exdis exdis commented Jul 11, 2022

Fixes #78

@exdis exdis requested a review from lahmatiy July 11, 2022 09:09
src/content/init.js Outdated Show resolved Hide resolved
src/content/init.js Outdated Show resolved Hide resolved
src/content/init.js Show resolved Hide resolved
}).json;
const json = await data;

window.__discoveryPreloader = preloader; // eslint-disable-line no-underscore-dangle
Copy link
Member

Choose a reason for hiding this comment

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

I suppose there is no need to expose preloader, since we just do preloader.el.remove() we can do it right before initDiscovery check

Copy link
Member Author

@exdis exdis Jul 11, 2022

Choose a reason for hiding this comment

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

We have to wait for the discovery initialization. In the case of the fallback, this happens in a separate context, so I pass it through global. Tested it on large JSONs

Copy link
Member

Choose a reason for hiding this comment

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

Well, preloader is needed while data is loading. Is it actual when data is loaded?

Copy link
Member Author

@exdis exdis Jul 11, 2022

Choose a reason for hiding this comment

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

Sure. Otherwise the loading will stop at data parsing step and you will see the Discovery immediately (skipping the init ui, prepare etc steps)

if (typeof initDiscovery !== 'function') {
await chrome.runtime.sendMessage({ type: 'initDiscovery' });
} else {
await initDiscovery(...window.__discoveryOptions);
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion:

const discoveryOptions = {...};

if (typeof initDiscovery !== 'function') {
  window.__discoveryOptions = discoveryOptions;
  chrome.runtime.sendMessage({ type: 'initDiscovery' });
} else {
  initDiscovery(...discoveryOptions);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed


preloader.el.remove();
const { initDiscovery } = await import(chrome.runtime.getURL('discovery-esm.js'));
Copy link
Member

Choose a reason for hiding this comment

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

I believe you should try revert to Promise.all()

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted

preloader.el.remove();
const { initDiscovery } = await import(chrome.runtime.getURL('discovery-esm.js'));

if (typeof initDiscovery !== 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to add a comment what is going on here

Copy link
Member Author

Choose a reason for hiding this comment

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

Added comment

@exdis exdis merged commit a4cb96a into master Jul 15, 2022
@exdis exdis deleted the github-csp-fix branch July 15, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't view json if server using CSP sandbox
2 participants