Explain Codes LogoExplain Codes Logo

Re-enabling window.alert in Chrome

javascript
debugging
chrome-devtools
javascript-errors
Nikita BarsukovbyNikita BarsukovΒ·Sep 15, 2024
⚑TLDR

Get your window.alert back in Chrome in a jiffy with this one-liner:

let originalAlert = window.alert.bind(window); window.alert = (...args) => originalAlert(...args); // "Proof of life"πŸ˜‰ console.log("I'm alive!");

Here originalAlert refers to the native alert function of Chrome. Copy, paste and run this in Chrome's developer console. This resuscitates your standard alert functionality.


Initial scrutiny

Before diving deep, let's run some basic health checks:

  • Chrome Settings: Confirm if settings or installed extensions in Chrome have deliberately silenced the alerts. Look into chrome://settings/content/notifications.
  • JavaScript Errors: Debug with a console.log to fish out any blunders muzzling your alerts.
  • Browser Testing: Run your window.alert in different browsers to diagnose if it's a Chrome-specific flu.

Deeper diagnosis

If the cure wasn't simple as we thought, here's a split up of the possible chrome ailments we should consider:

Chrome settings reset

Resuscitating Chrome to its plain vanilla settings helps discard any local configurations hindering alerts:

  1. Enter chrome://settings/reset in the address bar.
  2. Press Restore settings to their original defaults.
  3. Confirm by clicking Reset settings.

Clear browsing history

Sometimes your browser's past haunts the present. Corrupted data may pose issues with JavaScript outputs:

  1. Navigate to chrome://settings/clearBrowserData.
  2. Check both boxes: Cached images and files and Cookies and other site data.
  3. Select Clear data.

Then, refresh your web page for the changes to take effect.

Extensions and overrides

Extensions may hijack functionality, while DevTools can assert overrides on script execution:

  • Disable extensions one by one to fish out the meddler.
  • Leverage Chrome DevTools: Enter F12 -> Sources -> Overrides to reveal any scripts intentionally sabotaging the alerts.