diff --git a/package-lock.json b/package-lock.json index 5ec3e91..ff592f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@testing-library/jest-dom": "^5.11.9", "@testing-library/react": "^11.2.3", "@testing-library/user-event": "^12.6.2", - "@types/chrome": "0.0.128", + "@types/chrome": "^0.0.145", "@types/jest": "^26.0.20", "@types/node": "^14.14.22", "@types/react": "^17.0.0", @@ -2691,9 +2691,9 @@ } }, "node_modules/@types/chrome": { - "version": "0.0.128", - "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.128.tgz", - "integrity": "sha512-eGc599TDtersMBW1cSnExHm0IHrXrO5xdk6Sa2Dq30ED+hR1rpT1ez0NNcCgvGO52nmktGfyvd3Uyquzv3LL4g==", + "version": "0.0.145", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.145.tgz", + "integrity": "sha512-vLvTMmfc8mvwOZzkmn2UwlWSNu0t0txBkyuIv8NgihRkvFCe6XJX65YZAgAP/RdBit3enhU2GTxCr+prn4uZmA==", "dependencies": { "@types/filesystem": "*", "@types/har-format": "*" @@ -18815,6 +18815,7 @@ "version": "1.2.13", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", + "hasInstallScript": true, "optional": true, "os": [ "darwin" @@ -19423,6 +19424,7 @@ "version": "1.2.13", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", + "hasInstallScript": true, "optional": true, "os": [ "darwin" @@ -22934,9 +22936,9 @@ } }, "@types/chrome": { - "version": "0.0.128", - "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.128.tgz", - "integrity": "sha512-eGc599TDtersMBW1cSnExHm0IHrXrO5xdk6Sa2Dq30ED+hR1rpT1ez0NNcCgvGO52nmktGfyvd3Uyquzv3LL4g==", + "version": "0.0.145", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.145.tgz", + "integrity": "sha512-vLvTMmfc8mvwOZzkmn2UwlWSNu0t0txBkyuIv8NgihRkvFCe6XJX65YZAgAP/RdBit3enhU2GTxCr+prn4uZmA==", "requires": { "@types/filesystem": "*", "@types/har-format": "*" diff --git a/package.json b/package.json index 1198aef..389d6f1 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@testing-library/jest-dom": "^5.11.9", "@testing-library/react": "^11.2.3", "@testing-library/user-event": "^12.6.2", - "@types/chrome": "0.0.128", + "@types/chrome": "^0.0.145", "@types/jest": "^26.0.20", "@types/node": "^14.14.22", "@types/react": "^17.0.0", diff --git a/public/manifest.json b/public/manifest.json index 66c232f..0bbcedd 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,5 +1,5 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "Jira Software Tool", "short_name": "jira-software-tool", "description": "A Google Chrome extension for Jira Software. Easily copy issue/ ticket ID, title and URL to clipboard.", @@ -8,15 +8,10 @@ "permissions": [ "activeTab", "tabs", - "declarativeContent" + "declarativeContent", + "scripting" ], - "background": { - "scripts": [ - "chrome/background.js" - ], - "persistent": false - }, - "page_action": { + "action": { "default_popup": "index.html?page=Popup", "default_title": "Open Jira Software Tool" }, diff --git a/src/App.tsx b/src/App.tsx index 6dd0c21..232fbde 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,7 @@ import ErrorBoundary from "./boundaries/ErrorBoundary"; import ThemeProvider from "./providers/ThemeProvider"; import useChromeManifest from "./hooks/useChromeManifest"; -const App = ({ page }: { page: string }) => { +const App = ({ page = "Options" }: { page: string }) => { const manifest = useChromeManifest(); const Page = React.lazy(() => import(`./pages/${page}`)); diff --git a/src/hooks/useChromeManifest.tsx b/src/hooks/useChromeManifest.tsx index b2658c0..7841983 100644 --- a/src/hooks/useChromeManifest.tsx +++ b/src/hooks/useChromeManifest.tsx @@ -6,7 +6,7 @@ const useChromeManifest = () => { const loadManifest = async () => { const manifestData = - typeof chrome.runtime.getManifest === "function" + typeof chrome.runtime?.getManifest === "function" ? chrome.runtime.getManifest() : // Fallback to get manifest via `fetch` if `chrome.runtime.getManifest` is undefined await import("../utils/ApiRequests").then(({ getManifest }) => diff --git a/src/hooks/useTicketWithChrome.tsx b/src/hooks/useTicketWithChrome.tsx index 564fe4b..2ee9efa 100644 --- a/src/hooks/useTicketWithChrome.tsx +++ b/src/hooks/useTicketWithChrome.tsx @@ -12,22 +12,31 @@ const useTicketWithChrome = () => { React.useEffect(() => { if (typeof chrome.tabs !== "undefined") { - chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { - // console.log(tabs); - // Get ticket details result from DOM - chrome.tabs.executeScript( - { code: `(${getTicketFromDOM})();` }, - (results) => { - const ticket = results[0]; - const { issueTitle, issueID, issueURL } = ticket; + chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => { + try { + // Get ticket details result from DOM + chrome.scripting.executeScript( + { + target: { + tabId: tab.id ?? chrome.tabs.TAB_ID_NONE, + allFrames: true, + }, + function: getTicketFromDOM, + }, + (results) => { + const { result } = results[0]; + const { issueTitle, issueID, issueURL } = result; - setTicket({ - issueTitle, - issueID, - issueURL, - }); - } - ); + setTicket({ + issueTitle, + issueID, + issueURL, + }); + } + ); + } catch (error) { + console.log("Script execution error: ", error); + } }); } }, []); diff --git a/tsconfig.chrome.webpack.json b/tsconfig.chrome.webpack.json index 53fa4ff..d4f1f4b 100644 --- a/tsconfig.chrome.webpack.json +++ b/tsconfig.chrome.webpack.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "outDir": "./build/chrome/", + "outDir": "./build/", "noImplicitAny": true, "module": "esnext", "target": "es5", diff --git a/webpack.chrome.config.js b/webpack.chrome.config.js index b048992..2252996 100644 --- a/webpack.chrome.config.js +++ b/webpack.chrome.config.js @@ -14,7 +14,7 @@ module.exports = { }, output: { filename: "[name].js", - path: path.resolve(__dirname, "./build/chrome/"), + path: path.resolve(__dirname, "./build/"), }, module: { rules: [