Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

clipper: get rid of `<all_urls>` permission

Abdullah Atta68b3ebe31890
diff --git a/extensions/web-clipper/build-utils/manifest.js b/extensions/web-clipper/build-utils/manifest.js
index a343eaff1..10ccad224 100644
--- a/extensions/web-clipper/build-utils/manifest.js
+++ b/extensions/web-clipper/build-utils/manifest.js
@@ -36,7 +36,7 @@ const common = {
version: "0.2",
description:
"Clip web pages & save interesting things you find on the web directly into Notesnook in a private & secure way.",
- permissions: ["activeTab", "tabs", "storage", "notifications", "<all_urls>"],
+ permissions: ["activeTab", "tabs", "storage", "notifications"],
content_scripts: [
{
js: ["nnContentScript.bundle.js"],
@@ -59,6 +59,7 @@ const common = {
const v2 = {
...common,
+ optional_permissions: ["http://*/*", "https://*/*"],
browser_specific_settings: {
gecko: {
strict_min_version: "105.0"
@@ -73,6 +74,7 @@ const v2 = {
const v3 = {
...common,
+ optional_host_permissions: ["http://*/*", "https://*/*"],
manifest_version: 3,
background: {
service_worker: BACKGROUND_SCRIPT
diff --git a/extensions/web-clipper/src/views/main.tsx b/extensions/web-clipper/src/views/main.tsx
index 43afc510e..13e991c5e 100644
--- a/extensions/web-clipper/src/views/main.tsx
+++ b/extensions/web-clipper/src/views/main.tsx
@@ -96,6 +96,7 @@ export function Main() {
const [settings] = usePersistentState<Config>(SETTINGS_KEY, DEFAULT_SETTINGS);
const [title, setTitle] = useState<string>();
+ const [hasPermission, setHasPermission] = useState<boolean>(false);
const [url, setUrl] = useState<string>();
const [clipNonce, setClipNonce] = useState(0);
const [clipMode, setClipMode] = usePersistentState<ClipMode>(
@@ -150,6 +151,55 @@ export function Main() {
})();
}, [isPremium, clipArea, clipMode, clipNonce]);
+ useEffect(() => {
+ (async () => {
+ if (!settings || !settings.corsProxy) return;
+ setHasPermission(
+ await browser.permissions.contains({
+ origins: [`${settings.corsProxy}/*`]
+ })
+ );
+ })();
+ }, [settings]);
+
+ if (!hasPermission) {
+ <FlexScrollContainer style={{ maxHeight: 560 }}>
+ <Flex
+ sx={{
+ flexDirection: "column",
+ p: 2,
+ width: 320,
+ backgroundColor: "background"
+ }}
+ >
+ <Text
+ variant="subtitle"
+ sx={{ mt: 2, mb: 1, color: "icon", fontSize: "body" }}
+ >
+ Permission required
+ </Text>
+ <Button
+ onClick={async () => {
+ if (settings?.corsProxy) {
+ if (
+ !(await browser.permissions.request({
+ origins: [`${settings.corsProxy}/*`]
+ }))
+ )
+ throw new Error(
+ "You must give the required permission in order to use the web clipper."
+ );
+
+ setHasPermission(true);
+ }
+ }}
+ >
+ Grant permission
+ </Button>
+ </Flex>
+ </FlexScrollContainer>;
+ }
+
return (
<FlexScrollContainer style={{ maxHeight: 560 }}>
<Flex