-
Notifications
You must be signed in to change notification settings - Fork 201
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
Enforce non-empty configuration when boot script is run from the browser extension #5392
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5392 +/- ##
=======================================
Coverage 99.19% 99.19%
=======================================
Files 237 237
Lines 9403 9403
Branches 2243 2243
=======================================
Hits 9327 9327
Misses 76 76 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
Since the code is super simple and easy to change, I think this is OK. If we find it causes a problem we can revise it. |
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.
LGTM in principle. See suggestion for revised message.
const isExtensionContext = !!( | ||
/** @type {any} */ (window).chrome?.runtime?.id | ||
); | ||
if (!Object.keys(config).length && isExtensionContext) { |
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.
It is possible the page may contain its own Hypothesis configuration. What we really want to check for here is the config that corresponds to the specific extension being used. One way to do this might be to add an attribute to the configuration <script>
indicating the ID of the extension
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.
Yeah, you are right. In fact I run into this while testing on a page that precisely had its own config and it took me some attempts to realize what was going on 😅
I like the idea of the attribute with the extension ID. I'm going to merge this as is, address your suggestion in the browser extension, and then come back here and improve it.
Thanks!.
src/boot/index.js
Outdated
); | ||
if (!Object.keys(config).length && isExtensionContext) { | ||
throw new Error( | ||
'Could not bootstrap hypothesis as there is no configuration' |
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.
'Could not bootstrap hypothesis as there is no configuration' | |
'Could not start Hypothesis extension as configuration is missing' |
Tweaked this wording to capitalize Hypothesis, mention the extension specifically, and prefer start or launch as probably more meaningful than "bootstrap" for users rather than developers of Hypothesis.
4c99404
to
c7fde3c
Compare
This is an attempt to work around what's described in hypothesis/browser-extension#1179
This would cover only the usage of the browser extension in webs. For PDFs, a similar check needs to be done in the pdfjs-init, where we can directly prevent the loading of the boot script if there's no config.
Considerations on this PR / topics to discuss.
Testing steps
make build && npx yalc publish
.npx yalc add hypothesis
.injectConfig
from theinjectIntoHTML
function:make build SETTINGS_FILE=settings/<custom.json>