diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
index 6382756..36e3734 100644
--- a/.github/workflows/nodejs.yml
+++ b/.github/workflows/nodejs.yml
@@ -17,4 +17,4 @@ jobs:
- run: npm install -g web-ext # build tool
- run: npm run build-chrome
- run: npm run build-firefox
- - run: npm run build-firefox-mv2
+ - run: npm run build-firefox-mv3
diff --git a/.gitignore b/.gitignore
index 5631d21..ca48121 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,10 @@
.DS_Store
node_modules/
build/*
+firefox-mv3/dist/*
+!firefox-mv3/dist/.keep
firefox/dist/*
!firefox/dist/.keep
-firefox-mv2/dist/*
-!firefox-mv2/dist/.keep
chrome/dist/*
!chrome/dist/.keep
.nyc_output
diff --git a/.idea/copy-as-markdown.iml b/.idea/copy-as-markdown.iml
index ed9690d..664eda4 100644
--- a/.idea/copy-as-markdown.iml
+++ b/.idea/copy-as-markdown.iml
@@ -6,12 +6,12 @@
-
-
-
+
+
+
diff --git a/firefox-mv2/dist/.keep b/firefox-mv3/dist/.keep
similarity index 100%
rename from firefox-mv2/dist/.keep
rename to firefox-mv3/dist/.keep
diff --git a/firefox/hacks.js b/firefox-mv3/hacks.js
similarity index 100%
rename from firefox/hacks.js
rename to firefox-mv3/hacks.js
diff --git a/firefox-mv2/manifest.json b/firefox-mv3/manifest.json
similarity index 90%
rename from firefox-mv2/manifest.json
rename to firefox-mv3/manifest.json
index d1495c7..fbc8995 100644
--- a/firefox-mv2/manifest.json
+++ b/firefox-mv3/manifest.json
@@ -1,7 +1,7 @@
{
"name": "Copy as Markdown",
"version": "2.13.0",
- "manifest_version": 2,
+ "manifest_version": 3,
"description": "Copy Link or Image as Markdown code",
"permissions": [
"activeTab",
@@ -12,7 +12,7 @@
"storage",
"tabs"
],
- "browser_action": {
+ "action": {
"default_icon": {
"128": "./dist/images/icon-128.png"
},
@@ -26,8 +26,11 @@
"128": "./dist/images/icon-128.png"
},
"background": {
- "page": "background.html",
- "persistent": false
+ "scripts": [
+ "hacks.js",
+ "./dist/background.js"
+ ],
+ "type": "module"
},
"commands": {
"selection-as-markdown": {
@@ -67,7 +70,7 @@
"browser_specific_settings": {
"gecko": {
"id": "jid1-tfBgelm3d4bLkQ@jetpack",
- "strict_min_version": "60.0"
+ "strict_min_version": "112.0"
}
}
}
diff --git a/firefox-mv2/background.html b/firefox/background.html
similarity index 100%
rename from firefox-mv2/background.html
rename to firefox/background.html
diff --git a/firefox-mv2/create-menus.js b/firefox/create-menus.js
similarity index 100%
rename from firefox-mv2/create-menus.js
rename to firefox/create-menus.js
diff --git a/firefox/manifest.json b/firefox/manifest.json
index fbc8995..a78b45c 100644
--- a/firefox/manifest.json
+++ b/firefox/manifest.json
@@ -1,7 +1,7 @@
{
"name": "Copy as Markdown",
"version": "2.13.0",
- "manifest_version": 3,
+ "manifest_version": 2,
"description": "Copy Link or Image as Markdown code",
"permissions": [
"activeTab",
@@ -12,7 +12,7 @@
"storage",
"tabs"
],
- "action": {
+ "browser_action": {
"default_icon": {
"128": "./dist/images/icon-128.png"
},
@@ -26,11 +26,8 @@
"128": "./dist/images/icon-128.png"
},
"background": {
- "scripts": [
- "hacks.js",
- "./dist/background.js"
- ],
- "type": "module"
+ "page": "background.html",
+ "persistent": true
},
"commands": {
"selection-as-markdown": {
@@ -70,7 +67,7 @@
"browser_specific_settings": {
"gecko": {
"id": "jid1-tfBgelm3d4bLkQ@jetpack",
- "strict_min_version": "112.0"
+ "strict_min_version": "60.0"
}
}
}
diff --git a/jsconfig.json b/jsconfig.json
index 01cc24f..ddb2b3f 100644
--- a/jsconfig.json
+++ b/jsconfig.json
@@ -10,6 +10,7 @@
},
"include": [
"src/**/*",
- "node_modules/web-ext-types/global/index.d.ts", "chrome/environment.chrome.js", "firefox/environment.firefox.js"
+ "node_modules/web-ext-types/global/index.d.ts", "chrome/environment.chrome.js",
+ "firefox-mv3/environment.firefox.js"
]
}
diff --git a/package.json b/package.json
index 87c1657..59c23c3 100644
--- a/package.json
+++ b/package.json
@@ -6,8 +6,8 @@
"scripts": {
"test": "mocha",
"build-chrome": "sh compile.sh chrome && zip -r build/chrome.zip chrome/",
- "build-firefox-mv2": "sh compile.sh firefox-mv2 && npx web-ext build -s firefox-mv2/ -a build/firefox-mv2/",
"build-firefox": "sh compile.sh firefox && npx web-ext build -s firefox/ -a build/firefox/",
+ "build-firefox-mv3": "sh compile.sh firefox-mv3 && npx web-ext build -s firefox-mv3/ -a build/firefox-mv3/",
"debug-chrome": "npx nodemon --exec 'sh compile.sh chrome' & npx web-ext run -s chrome/ -t chromium --args chrome://extensions https://example.com",
"debug-edge": "npx nodemon --exec 'sh compile.sh chrome' & npx web-ext run -s chrome/ -t chromium --chromium-binary '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' --args chrome://extensions https://example.com",
"debug-firefox-mv2": "npx nodemon --exec 'sh compile.sh firefox-mv2' & npx web-ext run -s firefox-mv2/ --url about:debugging#/runtime/this-firefox https://example.com",
diff --git a/src/background.js b/src/background.js
index 09afbb0..fccde86 100644
--- a/src/background.js
+++ b/src/background.js
@@ -141,11 +141,14 @@ function getTurndownOptions() {
}
async function convertSelectionInTabToMarkdown(tab) {
- await chrome.scripting.executeScript({
+ // XXX: In Firefox MV2, executeScript() does not return results.
+ // We must use browser.scripting instead of chrome.scripting .
+ const entrypoint = (typeof browser !== 'undefined') ? browser.scripting : chrome.scripting;
+ await entrypoint.executeScript({
target: { tabId: tab.id, allFrames: true },
files: ['dist/vendor/turndown.js'],
});
- const results = await chrome.scripting.executeScript({
+ const results = await entrypoint.executeScript({
target: { tabId: tab.id, allFrames: true },
func: selectionToMarkdown,
args: [
diff --git a/src/lib/clipboard-access.js b/src/lib/clipboard-access.js
index b90df93..0b463a2 100644
--- a/src/lib/clipboard-access.js
+++ b/src/lib/clipboard-access.js
@@ -156,7 +156,11 @@ async function copy(text) {
*/
export default async function writeUsingContentScript(tab, text) {
return new Promise((resolve, reject) => {
- chrome.scripting.executeScript({
+ // XXX: In Firefox MV2, executeScript() does not return results.
+ // We must use browser.scripting instead of chrome.scripting .
+ const entrypoint = (typeof browser !== 'undefined') ? browser.scripting : chrome.scripting;
+
+ entrypoint.executeScript({
target: {
tabId: tab.id,
},
diff --git a/src/lib/settings.js b/src/lib/settings.js
index e38421f..b0dc74f 100644
--- a/src/lib/settings.js
+++ b/src/lib/settings.js
@@ -2,7 +2,7 @@ const SKLinkTextAlwaysEscapeBrackets = 'linkTextAlwaysEscapeBrackets';
const SKStyleOfUnorderedList = 'styleOfUnorderedList ';
/**
- * Singleton Settings object in the chrome.storage.sync storage
+ * Singleton Settings object in the sync storage
*/
export default {
/**
@@ -10,21 +10,21 @@ export default {
* @return {Promise}
* */
async setLinkTextAlwaysEscapeBrackets(value) {
- await chrome.storage.sync.set({
+ await this.syncStorage.set({
[SKLinkTextAlwaysEscapeBrackets]: value,
});
this.publishUpdated();
},
async setStyleOfUnrderedList(value) {
- await chrome.storage.sync.set({
+ await this.syncStorage.set({
[SKStyleOfUnorderedList]: value,
});
this.publishUpdated();
},
async reset() {
- await chrome.storage.sync.clear();
+ await this.syncStorage.clear();
this.publishUpdated();
},
@@ -34,7 +34,7 @@ export default {
},
async getAll() {
- const all = await chrome.storage.sync.get({
+ const all = await this.syncStorage.get({
[SKLinkTextAlwaysEscapeBrackets]: false,
[SKStyleOfUnorderedList]: 'dash',
});
@@ -44,4 +44,16 @@ export default {
styleOfUnorderedList: all[SKStyleOfUnorderedList],
};
},
+
+ /**
+ * @returns {chrome.storage.SyncStorageArea|browser.storage.StorageArea}
+ */
+ get syncStorage() {
+ // XXX: in Firefox MV2 the implementation of chrome.storage.sync
+ // always return undefined. We must use browser.storage.sync .
+ if (typeof browser !== 'undefined') {
+ return browser.storage.sync;
+ }
+ return chrome.storage.sync;
+ },
};