如何使用 JavaScript 打开扩展程序的弹出窗口?

问题描述:

我正在尝试编写一个 JavaScript 函数,它会像单击扩展程序图标一样打开我的扩展程序.我知道如何在新标签页中打开我的扩展程序:

I am trying to write a JavaScript function that will open my extension like when the extension icon is clicked. I know how to open my extension in a new tab:

var url = "chrome-extension://kelodmiboakdjlbcdfoceeiafckgojel/login.html";
window.open(url);

但是我想在浏览器的右上角打开一个弹出窗口,就像点击扩展程序图标一样.

But I want to open a pop-up in the upper right corner of the browser, like when the extension icon is clicked.

Chromium 开发团队明确表示他们不会启用此功能.请参阅功能请求:以编程方式打开扩展弹出气泡:

The Chromium dev team has explicitly said they will not enable this functionality. See Feature request: open extension popup bubble programmatically :

浏览器和页面操作弹出窗口的理念是它们必须由用户操作触发.我们的建议是使用新的 html 通知功能...

The philosophy for browser and page action popups is that they must be triggered by user action. Our suggestion is to use the new html notifications feature...

桌面通知可用于向用户展示一个小的 HTML页面很像您的弹出窗口.这不是一个完美的替代品,但它可能会提供您需要的功能类型.

Desktop notifications can be used progammatically to present the user with a small HTML page much like your popup. It's not a perfect substitution, but it might provide the type of functionality you need.