Fix “prompt() Is Not Supported” in JavaScript

prompt() is a method of the browser Window object. A code runner, editor output panel, Node.js process, worker, test environment, or restricted preview can execute JavaScript without providing browser dialogs. Run the script through the browser page or use an HTML input instead.

Last updated: October 9, 2026.

<form id="name-form">
  <label for="name">Your name</label>
  <input id="name" name="name" autocomplete="name" required>
  <button type="submit">Continue</button>
</form>
<p id="result" aria-live="polite"></p>

<script>
  const form = document.querySelector('#name-form');
  const result = document.querySelector('#result');

  form.addEventListener('submit', (event) => {
    event.preventDefault();
    const name = new FormData(form).get('name').trim();
    result.textContent = name ? 'Hello, ' + name + '!' : '';
  });
</script>

This works inside a normal browser document and does not block the page with a modal dialog. It also gives the input a label and lets the browser apply form validation.

Confirm where the script is executing

Open the page through the development server, then use the browser developer console. In a page script, globalThis === window is true and typeof window.prompt is normally function. If the editor runs the file itself, it may use Node.js or a sandbox with a deliberately unsupported stub.

MDN documents window.prompt() as a browser-window method that returns entered text or null. Checking only whether a global named prompt exists is not enough; a host can expose it but throw when called.

Prefer page controls for real interfaces

Modal prompts block interaction, have limited styling, and browsers may suppress them in some situations. A form field is easier to validate, test, translate, and make accessible. If you only need a quick learning exercise, call window.prompt() from a click handler in the browser and handle the null result.

Do not install a random package merely to imitate browser prompts in production code. Choose an input method supported by the actual runtime. Continue with tracing JavaScript errors, JavaScript form validation, and accessible keyboard handling.

Related Web Cheat Sheet guides

Sergey Kornilov

Sergey Kornilov