I am making a simple Chrome extension which will change the prototype of the Date
object. I want the flow to be like the following.
inject.js
loadsinject.js
runs and changessetHours
on theDate
prototype- The rest of the page will use the
setHours
that I have now defined
My inject.js
:
Date.prototype.setHours = function () {
alert();
};
My manifest.json
:
{
// ...
"content_scripts": [
{
"matches": ["*"],
"js": ["inject.js"],
"run_at": "document_start"
}
]
}
Note that I use the run_at
property to instruct the script to run before any JS is loaded on the page. This seems to work as I invoked debugger
and the page did not load.
I understand this may be explicitly blocked as it seems like it could maybe be a security issue? Though I have not seen any mention of modifying the prototype chain being disallowed.
I am unfortunately getting Cannot read properties of undefined (reading 'prototype')
Help would be greatly appreciated!