-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to inform the user of errors and progress from a Service Worker? #259
Comments
Opening a custom window via the Windows API seems nice: Similar code (but adapted to use the Windows API instead): var myWindow = window.open("", "", "width=500,height=150");
myWindow.document.write('<span>Huston we got a problem <button>Okay')
myWindow.document.body.style = 'justify-content: center;display: flex;align-items: center;'
// + centering But there's no way to add a script to enable an "Ok" button:
It seems that the only way to show custom content in a window is to load an HTML file that exists in the extension itself (or remote URL with permission). It seems that the minimum possible solution to this requires:
Is there any other way to achieve my example above without creating these files? |
You can open a new window using chrome.windows.create({url: 'alert.html?' + new URLSearchParams({data: 'foo'}), type: 'popup'}) then alert.html will build the UI and send the result back by messaging. |
I already described that solution:
Having to build and manage such a core functionality when |
Seems like we should consider an extension |
That's the path I would advise. As you described, the default extension CSP prevents developers from declaring the entire page inline. At the moment to implement this in a Chrome extension a developer would need to have static HTML and JS files.
I think that's a fair criticism. |
@fregante, while working on something else I just put together a quick proof of concept for an alert-like popup. Note that this window will have a let msg = `Well, that's one way to show an alert`;
let url = `data:text/html,\
<!DOCTYPE html>
<html>
<head>
<!-- If you don't specify a title, the data URL will appear in the title bar -->
<title>Alert Demo</title>
</head>
<body>
<p>${msg}</p>
<button id="close-button">Close</button>
<script>
const closeButton = document.getElementById('close-button');
// Close the popup if the user clicks the "close" button
closeButton.addEventListener('click', _ => window.close());
// Automatically close this popup if it loses focus
window.addEventListener('blur', _ => window.close());
</script>
</body>
</html>`
chrome.windows.create({url, type: "popup", height: 200, width: 300}) |
@dotproto it works in Chrome and Safari, but Firefox won't accept data URLs. 😰 Kinda disappointing because Firefox has never allowed I finally managed to publish a module that makes use of that technique as a fallback to For now I'll close this issue as there's a proposal for a new API to resolve this: If you have further ideas that might work on Firefox I'm all ears. |
I'm reposting this unresolved request from another now-archived repo.
Until now, when executing code from the
browser_action
orcontext_menu
(in background.js), you could either inject code into the current page or usealert
to communicate with the user.The first option is already limited since it only works if the extension has access to the tab and the second option already does not work in Firefox and Safari.
Do you have any alternatives for this since Service Workers don't have
alert()
at all?The text was updated successfully, but these errors were encountered: