Assuming you've been using textContent to run the script in page context, which is not allowed anymore, there are several MV3-compatible methods shown in
https://stackoverflow.com/a/9517879. And if you want to override it before any page script runs, use registerContentScripts in your service worker like this:
chrome.runtime.onInstalled.addListener(addPageScript);
async function addPageScript() {
const scripts = [{
id: 'override',
js: ['override.js'],
matches: ['<all_urls>'],
runAt: 'document_start',
world: 'MAIN',
}];
const ids = scripts.map(s => s.id);
await chrome.scripting.unregisterContentScripts({ ids }).catch(() => {});
await chrome.scripting.registerContentScripts(scripts);
}
Now override.js can modify `alert` directly:
window.alert = console.log.bind(null, 'alert:');