Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
97686411
Commit
97686411
authored
Apr 18, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Apr 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve how we detect if the boot script is run by certain browser extension
parent
e186dc8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
6 deletions
+29
-6
browser-extension-utils.js
src/boot/browser-extension-utils.js
+24
-0
index.js
src/boot/index.js
+5
-6
No files found.
src/boot/browser-extension-utils.js
0 → 100644
View file @
97686411
/**
* Tries to get the extension ID which is running this script, or undefined if
* this script is not being run by the browser extension
*
* @param {Window} window_
* @return {string | undefined}
*/
export
function
getExtensionId
(
window_
=
window
)
{
return
/** @type {any} */
(
window_
).
chrome
?.
runtime
?.
id
;
}
/**
* Verifies if there's a config script in the document that was generated by a
* specific extension
*
* @param {string} extensionId
* @param {Document} document_
* @return {boolean}
*/
export
function
hasExtensionConfig
(
extensionId
,
document_
=
document
)
{
return
!!
document_
.
querySelector
(
`script.js-hypothesis-config[data-extension-id=
${
extensionId
}
]`
);
}
src/boot/index.js
View file @
97686411
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
import
manifest
from
'../../build/manifest.json'
;
import
manifest
from
'../../build/manifest.json'
;
import
{
bootHypothesisClient
,
bootSidebarApp
}
from
'./boot'
;
import
{
bootHypothesisClient
,
bootSidebarApp
}
from
'./boot'
;
import
{
isBrowserSupported
}
from
'./browser-check'
;
import
{
isBrowserSupported
}
from
'./browser-check'
;
import
{
getExtensionId
,
hasExtensionConfig
}
from
'./browser-extension-utils'
;
import
{
parseJsonConfig
}
from
'./parse-json-config'
;
import
{
parseJsonConfig
}
from
'./parse-json-config'
;
import
{
processUrlTemplate
}
from
'./url-template'
;
import
{
processUrlTemplate
}
from
'./url-template'
;
...
@@ -22,12 +23,10 @@ if (isBrowserSupported()) {
...
@@ -22,12 +23,10 @@ if (isBrowserSupported()) {
parseJsonConfig
(
document
)
parseJsonConfig
(
document
)
);
);
// When the boot script is executed from the browser extension, at least one
// When the boot script is executed from the browser extension, a config
// config is required
// generated by that specific extension is required
const
isExtensionContext
=
!!
(
const
extensionId
=
getExtensionId
();
/** @type {any} */
(
window
).
chrome
?.
runtime
?.
id
if
(
extensionId
&&
!
hasExtensionConfig
(
extensionId
))
{
);
if
(
!
Object
.
keys
(
config
).
length
&&
isExtensionContext
)
{
throw
new
Error
(
throw
new
Error
(
'Could not start Hypothesis extension as configuration is missing'
'Could not start Hypothesis extension as configuration is missing'
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment