Cannot read properties of undefined in Chrome extension

Viewed 37

I am working on my first Chrome extension to popup an alert. On my background.js I get the following message when I add my files Chrome extentions: Uncaught TypeError: Cannot read properties of undefined (reading 'onAlarm').

'use strict';

function setAlarm() {
    let minutes = parseFloat($("#time").val())
    chrome.alarms.create('reminderAlarm', {
        periodInMinutes: minutes
    })
    window.close()
}

$("#submit").click(setAlarm)

Any idea how to fix it? I attach an image of the error and code.

Error message

1 Answers

the value of the variable your function is trying to read is "undefined". in other words value is not assigned to the variable before it was read. to debug: console.log("whatever is undefined") then find the reason.

it is difficult to spot problem without seeing the code.

add to manifest.json

"permissions":["alarms"],
Related