If you aren't worried about the entered text being displayed without ***s, then it looks fine. It'll be as safe as pretty much any other JS handling of passwords.
Can other websites have access to the content of this prompt
If it's a content script, they could, if they intercepted the window.prompt and overwrote it with their own implementation, eg:
// page script:
const originalPrompt = window.prompt;
window.prompt = (text) => {
const result = originalPrompt(text);
// HERE, the page can do something malicious with the result
// such as sending it to their server
console.log('Page detected:', result);
return result;
};
// Your script:
prompt('Password?');
But this approach would compromise pretty much any handling of passwords on the front-end - it's not an issue with the prompt, but with the front-end in general.
To get around this problem in a content script, make sure that the prompt that you call is the native code version, which can only be done in a foolproof way by running your code before any other code on the page runs. Save a reference to the original prompt on document_start.
Also, make sure to do the validation on the backend, not the frontend. If your JS is like
const userInput = prompt("enter password");
if (userInput !== 'theTruePassword') {
// wrong
return;
}
// do stuff
then it would be trivial for anyone with access to the website to bypass the password check and get to the do stuff by examining the source code. Instead, make sure to send the password to a server and have the server validate whether it's correct, then have the server send the sensitive information back to the client.