0

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.

1 Answers1

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