Skip to content

Commit

Permalink
Support manifest v3
Browse files Browse the repository at this point in the history
  • Loading branch information
workeffortwaste committed May 18, 2022
1 parent 432e349 commit fef9bb2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
25 changes: 21 additions & 4 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ async function getLocalStorageValue (key) {
})
}

const runtimeInjection = async (settings) => {
window.vitalsLevel = settings.level
window.cruxKey = settings.cruxKey
window.vitalsDevice = settings.vitalsDevice
}

chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.status === 'complete' && tab.url !== undefined) {
const cruxKey = await getLocalStorageValue('apiKey')
Expand All @@ -23,10 +29,21 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (Object.keys(device).length === 0) { device = { deviceSettings: 'PHONE' } }
if (Object.keys(level).length === 0) { level = { levelSettings: 'URL' } }

chrome.tabs.executeScript(tab.id, {
code: 'window.vitalsLevel = "' + level.levelSettings + '"; window.cruxKey = "' + cruxKey.apiKey + '"; window.vitalsDevice = "' + device.deviceSettings + '"'
}, function () {
chrome.tabs.executeScript(tab.id, { file: 'bundle.js' })
const settings = {
cruxKey: cruxKey.apiKey,
level: level.levelSettings,
vitalsDevice: device.deviceSettings
}

chrome.scripting.executeScript({
target: { tabId: tab.id },
func: runtimeInjection,
args: [settings]
}, () => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['bundle.js']
})
})
}
})
8 changes: 5 additions & 3 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "Core SERP Vitals",
"icons": { "128": "icon128.png"},
"version": "1.2.3",
"description": "Show the Core Web Vitals data from the Chrome User Experience Report in the Google Search Results.",
"background": {
"scripts" : ["background.js"],
"persistent": true
"service_worker" : "background.js"
},
"options_page": "options.html",
"permissions": [
"storage",
"activeTab",
"scripting"
],
"host_permissions": [
"https://www.google.com/search?*",
"https://www.google.co.uk/search?*",
"https://www.google.de/search?*",
Expand Down

0 comments on commit fef9bb2

Please sign in to comment.