I want to make a Chrome extension that when the user requests mysite/file.js
it will replace the alert('hi')
to alert('bye')
. I can't figure this out I am new at Chrome Extensions. Thanks.
Asked
Active
Viewed 1,707 times
0

Elijah Porter
- 3
- 4
1 Answers
0
I think there might be better ways to achieve what you need, depending on your use case.
For example, you could inject a content script that overrides alert
on the page world.
context.js
const script = document.createElement('script');
script.innerHTML = `
const originalAlert = window.alert;
window.alert = (msg) => {
originalAlert(msg === 'hello' ? 'bye' : msg);
};
`;
document.body.appendChild(script);

Danziger
- 19,628
- 4
- 53
- 83
-
1Sorry for such a late reply (I don't check this ever). That is what I ended up doing :p – Elijah Porter Aug 01 '19 at 23:51