Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

The openPopup method is undefined in Chrome 100.0.4896.75 yet the doc says otherwise. #2602

Closed
nibble0101 opened this issue Apr 14, 2022 · 54 comments
Assignees
Labels
content extensions Issues related to extensions documentation. extensions-reference Items that require update in Code Source P2 A normal priority task. This is the default for most issues.

Comments

@nibble0101
Copy link

Describe the bug
According to the documentation, the openPopup method should be available in Chrome 99+ but I get the Uncaught TypeError: chrome.action.openPopup is not a function error when I run the code below.

chrome.runtime.onInstalled.addListener(() => {
  console.log("Immediately");
  setTimeout(() => {
    console.log("After 10s");
    console.log(chrome.action.openPopup); // undefined
    chrome.action.openPopup();
  }, 10000);
});

Below is my manifest.json file.

{
    "name": "dewall",
    "description": "Removes paywall on select websites",
    "version": "1.0",
    "manifest_version": 3,
    "background": {
        "service_worker": "background.js"
    },
    "permissions": [
        "storage",
        "notifications"
    ],
    "action": {
        "default_popup": "popup.html",
        "default_icon": {
            "16": "/images/get_started16.png",
            "32": "/images/get_started32.png",
            "48": "/images/get_started48.png",
            "128": "/images/get_started128.png"
        }
    }
}

I am using 100.0.4896.75 (Official Build) (64-bit) . Either the way I am using the openPopup method is incorrect or the documentation is incorrect.

To Reproduce
Steps to reproduce the behavior:

  1. Create a basic extension using MV3
  2. Add the code above in background.js

Expected behavior
The extension will throw the Uncaught TypeError: chrome.action.openPopup is not a function error after 10s. I would have expected openPopup to not be undefined.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Pop!_os
  • Browser: Chrome
  • Version: 100.0.4896.75 (Official Build) (64-bit)

Smartphone (please complete the following information):
N/A

Additional context
N/A

@nibble0101 nibble0101 added bug Something on the site is broken! P2 A normal priority task. This is the default for most issues. labels Apr 14, 2022
@jeffposnick jeffposnick added the extensions Issues related to extensions documentation. label Apr 14, 2022
@jeffposnick
Copy link
Contributor

CC: @dotproto to confirm whether this is a documentation issue or something else.

@myersgm
Copy link

myersgm commented Apr 25, 2022

Experiencing the same issue in both chrome and edge. I have verified that my browsers are up to date.

Please update with a timeline for when chrome.action.openPopup will be available and update the docs to reflect the current status.

@xde013
Copy link

xde013 commented Apr 27, 2022

To avoid any bad surprises, I believe the openPopp() is only available inside of a user triggered event handler as explained here. Also MDN documentation seems to have very good explanation about Chrome API usage.

@nibble0101
Copy link
Author

nibble0101 commented Apr 27, 2022

To avoid any bad surprises, I believe the openPopp() is only available inside of a user triggered event handler as explained here. Also MDN documentation seems to have very good explanation about Chrome API usage.

Have you tried this in chrome? Because I still get undefined even in chrome.action.onClicked.

chrome.action.onClicked.addListener((tab) => {
  console.log(chrome.action.openPopup); // undefined
});

@xde013
Copy link

xde013 commented Apr 27, 2022

@nibble0101 I was wrong on my last statement. After doing some research it appears that Chrome's action.openPopup() is supposed to be more relaxed about user actions than Mozilla's browserAction.open(). Currently action.openPopup() seems to be missing from stable channel. See comment

@nibble0101
Copy link
Author

@nibble0101 I was wrong on my last statement. After doing some research it appears that Chrome's action.openPopup() is supposed to be more relaxed about user actions than Mozilla's browserAction.open(). Currently action.openPopup() seems to be missing from stable channel. See comment

Okay thanks.

@WagnerMoreira
Copy link

this is really weird, the function is listed in the docs but it's not available yet. how is that possible?

@robbi73
Copy link

robbi73 commented Jun 7, 2022

I made some tries with canary and it seems that second parameter (windowId) is useless.
it'd seem that only focused tab can open the popup

@myersgm
Copy link

myersgm commented Jul 21, 2022

Just tried this again in both stable versions of Edge and Chrome. The openPopup function is still undefined.

Is there any official update on this? Is this even the proper place to report such a bug? If not, please advise on where to report this so that it can be addressed.

@shaokeyibb
Copy link

Same issue, anything new now?

@elijaholmos
Copy link

also having this issue... is there any other way to programmatically trigger a popup opening?

@juancampa
Copy link

juancampa commented Aug 25, 2022

This doesn't work in other contexts either, even if they are user-triggered, such as a listener of chrome.commands.onCommand

Chrome version: Version 104.0.5112.101 (Official Build) (arm64)

@devnook devnook added the content label Sep 5, 2022
@myersgm
Copy link

myersgm commented Oct 3, 2022

Just checked again a couple months later and this is still happening.

Some transparency on the status of this bug would be much appreciated.

@DarkEye123
Copy link

DarkEye123 commented Oct 22, 2022

Still present. Is there no other way?

For now I open new tab with popup URL to do some actions I need. But that is not very pleasant UX

@stefanvd
Copy link
Contributor

Are there any updates here? Because this prevents me from publishing my Chrome extensions, chrome.action.openPopup() is not available in the Chrome stable (version 106.0.5249.119):

I did the test on my Manifest V3 Print Chrome extension that is already on the Chrome Web Store:
https://chrome.google.com/webstore/detail/print-for-google-chrome/idfnpgjblkahngbondojabhffkkdekbd
But my "double click" menu does not work on the Chrome stable channel, but it does work on the Chrome Dev channel.

I want to publish my Chrome extensions before the end of this year.

@robbi73
Copy link

robbi73 commented Oct 28, 2022

on 7 Jun I wrote: "... it'd seem that only focused tab can open the popup ..."
You have to put first the focus on the right window (no devtools windows).
A good workaround could be this:
chrome.tabs.getCurrent(tab => {
chrome.windows.update(tab.windowId, {focused:true}, _ => chrome.action.openPopup())
})

@anilf01
Copy link

anilf01 commented Nov 2, 2022

chrome.action.openPopup() work in chromium browser Version 106.0.5249.91 and chrome dev Version 108.0.5343.2.
but don't work on brave browser( chromium version Version 106.0.5249.103).

@itskaiway
Copy link

chrome.action.openPopup() work in chromium browser Version 106.0.5249.91 and chrome dev Version 108.0.5343.2. but don't work on brave browser( chromium version Version 106.0.5249.103).

Still not working on stable version (107.0.5304.88)

@jpmedley jpmedley added extensions-reference Items that require update in Code Source and removed bug Something on the site is broken! labels Nov 10, 2022
@chuanqisun
Copy link

This is also broken for Edge 107.0.1418.42

@TomVoxsen
Copy link

TomVoxsen commented Dec 2, 2022

chrome.action.openPopup() work in chromium browser Version 106.0.5249.91 and chrome dev Version 108.0.5343.2. but don't work on brave browser( chromium version Version 106.0.5249.103).

Still not working on stable version (107.0.5304.88)

Seconded. Works in Chromium Version 108.0.5359.71 but not Chrome Version 107.0.5304.110.

Calling from an onMessage listener within the Service Worker:

chrome.runtime.onMessage.addListener(
  // Open extension popup
  if (typeof chrome.action.openPopup === 'function') {
    console.log("Open the popup");
    chrome.action.openPopup({}, function() {
      console.log("Popup opened");
    });
  }
  else {
    console.log("chrome.action.openPopup() not supported");
  }
);

@addeective
Copy link

@oliverdunk can you please advise ? this is a really key feature for many addons.

WebGL3D added a commit to roblox-plus/extension that referenced this issue Mar 5, 2023
I may not be able to support this feature if chrome doesn't actually support openPopup.

See: GoogleChrome/developer.chrome.com#2602
@oliverdunk
Copy link
Member

Hey all 👋

Sorry for the confusion here - this API is currently only available in the dev channel. It's showing on https://developer.chrome.com/ because we automatically generate certain parts of the documentation from the features available in Chromium, and it seems like that tool doesn't yet have handling for a situation like this. I'll try to get that fixed.

If you want to track work on the API in general, you can star https://crbug.com/1245093. I don't have any updates to share but we're aware this is something that's in demand and I would personally really love to see it!

@oliverdunk
Copy link
Member

I've merged a fix so the docs are now showing the correct channel information: https://developer.chrome.com/docs/extensions/reference/action/#method-openPopup. Closing this in favour of https://crbug.com/1245093 :)

@aghwotu
Copy link

aghwotu commented Apr 25, 2023

A workaround for anyone still looking:

// here we check if we are on the Google home page or not
function setPopupForTab(tab) {
  if (tab.url.startsWith('https://www.google.com/')) {
    chrome.action.setPopup({ tabId: tab.id, popup: 'popup.html' });
  } else {
    chrome.action.setPopup({ tabId: tab.id, popup: 'errorPopup.html' });
  }
}

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
  if (changeInfo.status === 'complete') {
    setPopupForTab(tab);
  }
});

chrome.tabs.onActivated.addListener((activeInfo) => {
  chrome.tabs.get(activeInfo.tabId, (tab) => {
    setPopupForTab(tab);
  });
});

@celebritydeveloper
Copy link

celebritydeveloper commented Apr 25, 2023

Is there another way to open the chrome extension other than use the extension icon? I have a project of an extension where the webpages get buttons injected that send messages that reaches background script, and then I need to open the chrome extension programmatically. This is the final piece that is missing to build this user experience flow.

I can help if you want.

chrome.runtime.onInstalled.addListener(() => {
chrome.action.setPopup({
popup: "popup.html"
});
})

Make sure you remove the default_popup from the action object in manifest.json else it will not work.

@carloshpds
Copy link

carloshpds commented Aug 6, 2023

Hi guys,
If in your case you're using same app/popup for options page, you can use runtime.openOptionsPage() in your service worker for manifest v3 (or background script in manifest v2).

In your content script you will use sendMessage:

window.chrome.runtime.sendMessage({ type: 'OPEN_OPTIONS_PAGE' })

And in your service worker:

self.chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    if(message.type === 'OPEN_OPTIONS_PAGE'){
       self.chrome.runtime.openOptionsPage().then(() => {
         sendResponse('OPENED')
       }).catch((e) => {
        sendResponse('FAILED_TO_OPEN', e)
       })
    }
})

It works on other browsers too. But may change the window.chrome for window.browser.

@LuisSantosColman
Copy link

Is there another way to open the chrome extension other than use the extension icon? I have a project of an extension where the webpages get buttons injected that send messages that reaches background script, and then I need to open the chrome extension programmatically. This is the final piece that is missing to build this user experience flow.

I can help if you want.

chrome.runtime.onInstalled.addListener(() => { chrome.action.setPopup({ popup: "popup.html" }); })

Make sure you remove the default_popup from the action object in manifest.json else it will not work.

The above doesn't seem to be opening the popup programmatically, it only sets it silently without opening it. Users still must actively click on the extension icon. Is there any workaround to open the extension popup programmatically at all? (without using chrome.windows.create)?

@oliverdunk
Copy link
Member

Is there any workaround to open the extension popup programmatically at all?

Hi Luis, we recently shipped the API for policy-installed extensions, so if your extension is always installed by enterprise policy you can use chome.action.openPopup(). Beyond that, I'm afraid this isn't currently possible. We would still like to ship the API but have some outstanding issues to address first.

@cpakken
Copy link

cpakken commented Oct 29, 2023

Is there any workaround to open the extension popup programmatically at all?

Hi Luis, we recently shipped the API for policy-installed extensions, so if your extension is always installed by enterprise policy you can use chome.action.openPopup(). Beyond that, I'm afraid this isn't currently possible. We would still like to ship the API but have some outstanding issues to address first.

@oliverdunk This API does not work in developer mode using unpacked loaded extensions. I assume I need Chrome from the DEV channel?

@oliverdunk
Copy link
Member

@oliverdunk This API does not work in developer mode using unpacked loaded extensions. I assume I need Chrome from the DEV channel?

You can use Chrome from any channel but your extension must be force installed by policy. You can use the update testing tool to do this locally: https://github.com/GoogleChromeLabs/extension-update-testing-tool

@DanielRuf
Copy link

@oliverdunk I see no information regarding the channel, only Chrome 118+ and I'm using Chrome 119.

grafik

@DanielRuf
Copy link

You can use Chrome from any channel but your extension must be force installed by policy.

That is very confusing. The Requires policy provides no further context for new developers. Why not add a link + popup on hover for this badge?

@oliverdunk
Copy link
Member

Why not add a link + popup on hover for this badge?

There should be a tooltip if you hover for a few seconds - unfortunately we can't add a link or reduce the delay, but hopefully that helps somewhat. I definitely appreciate that the state of this is slightly confusing - I really hope we can release this to everyone soon because that would be the best fix 🙂

@DanielRuf
Copy link

Thanks, waiting a bit longer definitely shows some short tooltip.

The commit at https://bugs.chromium.org/p/chromium/issues/detail?id=1245093#c30 mentions "enterprise-installed extensions". I was not aware of the fact, that there is some differentiation for normal endusers and enterprise users in a company.

Seems this is some feature that is not available to normal users.

https://chromium.googlesource.com/chromium/src/+/HEAD/docs/enterprise/policies.md
https://source.chromium.org/chromium/chromium/src/+/main:docs/enterprise/add_new_policy.md

What exactly does that mean?
Is there some overview when a new feature is generally available?
How long will this be limited to enterprise policy users?

grafik

@oliverdunk
Copy link
Member

@DanielRuf, this is referring to the ability admins have to force-install extensions within an enterprise. An example would be the steps here: https://support.google.com/chrome/a/answer/6306504?hl=en

Releasing something for policy-installed extensions is independent of any release timeline, and unfortunately there aren't any updates there at the moment. I'd love for us to release this for everyone, and I think the whole team would, but we have some open issues to address beforehand.

@justingolden21
Copy link

Hoping to use this with context menus so I can add a context menu option to send data to the extension and open the extension.

@alyshae
Copy link

alyshae commented Dec 1, 2023

Hoping to use this with context menus so I can add a context menu option to send data to the extension and open the extension.

@justingolden21 have you had any luck implementing this with context menus?

@justingolden21
Copy link

I use this to send data to my notes app from right click to get the current selection and page title:

background script:

const CONTEXT_MENU_ID = 'addToNewNote';
// Register context menu option
chrome.contextMenus.create({
	title: 'Add "%s" to new note',
	contexts: ['selection'],
	id: CONTEXT_MENU_ID,
});

// Listen for context menu option clicked
chrome.contextMenus.onClicked.addListener(function (info, tab) {
	if (info.menuItemId === CONTEXT_MENU_ID) {
		// Create new tab of Chrome Notes
		chrome.tabs.create(
			{
				url: chrome.runtime.getURL('index.html'),
				active: true,
			},
			// Callback after creating tab to make sure it loaded before sending message
			function (newTab) {
				chrome.tabs.onUpdated.addListener(function (tabId) {
					if (tabId !== newTab.id) return;
					// If tab is loaded, send message
					chrome.runtime.sendMessage({
						action: 'new_note',
						title: tab.title,
						selection: info.selectionText,
					});
				});
				chrome.tabs.update(newTab.id, { active: true });
			}
		);
	}
});

script:

chrome.runtime.onMessage.addListener(function (message) {
	if (message.action === 'new_note') {
		// my code
	}
});

@alyshae hope this helps you and/or others!

@vdemcak
Copy link

vdemcak commented Dec 9, 2023

Any plans on releasing this feature to the general public? It has been more than 5 years since it was hidden under the #extension-apis flag

@sofent11
Copy link

waiting for this api can be public availabe

@Plentywolf
Copy link

Plentywolf commented Dec 22, 2023 via email

@oliverdunk
Copy link
Member

Any plans on releasing this feature to the general public?

There aren't any updates I'm afraid. We're still tracking this internally though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
content extensions Issues related to extensions documentation. extensions-reference Items that require update in Code Source P2 A normal priority task. This is the default for most issues.
Projects
None yet
Development

No branches or pull requests