Re: [crx] Chrome Crash When Calling chrome.sidePanel.open with windowId: chrome.windows.WINDOW_ID_CURRENT After Dynamically Requesting sidePanel Permission

79 views
Skip to first unread message
Message has been deleted

Oliver Dunk

unread,
Jun 20, 2025, 7:36:13 AMJun 20
to Neil Zhang, Chromium Extensions
Hi Neil,

I tried to reproduce the same behavior but I wasn't able to do so. Of course, if there is a crash, that definitely sounds like a bug and one that we should fix.

Can you make sure you are signed in to Google Chrome with a Google account and sync enabled, and then head to chrome://crashes/? You should see a "Uploaded crash report ID" which we can use to look into what happened. You may need to press "Send now" if it hasn't been uploaded already.

Thanks,
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


On Fri, Jun 20, 2025 at 12:07 PM 'Neil Zhang' via Chromium Extensions <chromium-...@chromium.org> wrote:

When dynamically requesting the sidePanel permission using chrome.permissions.request and then calling chrome.sidePanel.open({ windowId: chrome.windows.WINDOW_ID_CURRENT }), Google Chrome crashes consistently. This issue occurs in a Chrome extension using Manifest V3. The crash happens immediately after the chrome.sidePanel.open call, and no specific error message is logged before the browser terminates.

Chrome Version:

  • Google Chrome: [Insert your exact Chrome version here, e.g., 126.0.6478.127 (Official Build) (64-bit)]
  • Operating System: [Insert your OS, e.g., Windows 11, macOS Ventura 13.6, or Linux Ubuntu 22.04]

Steps to Reproduce:

  1. Create a Chrome extension with Manifest V3 and include the sidePanel permission in optional_permissions in manifest.json.
  2. Load the extension in Chrome using the "Load unpacked" option.
  3. Trigger a dynamic permission request for sidePanel using chrome.permissions.request.
  4. After the permission is granted, call chrome.sidePanel.open({ windowId: chrome.windows.WINDOW_ID_CURRENT }) to open the side panel.
  5. Observe that Chrome crashes immediately after the chrome.sidePanel.open call.

Expected Behavior:

  • The side panel should open in the current window without causing Chrome to crash.
  • If there is an issue with the API call, an error should be logged in the console (e.g., chrome.runtime.lastError) without terminating the browser.

Actual Behavior:

  • Chrome crashes entirely, closing all windows and tabs.
  • No error message is logged in the console before the crash, making it difficult to diagnose the root cause.

Code Example: Here is the relevant code used in the extension:

json
CollapseWrap
Copy
// manifest.json { "manifest_version": 3, "name": "Side Panel Crash Test", "version": "1.0", "optional_permissions": ["sidePanel"], "side_panel": { "default_path": "sidepanel.html" }, "background": { "service_worker": "background.js" } }
javascript
CollapseWrapRun
Copy
// background.js chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.action === "openSidePanel") { chrome.permissions.request( { permissions: ["sidePanel"], }, (granted) => { if (granted) { chrome.sidePanel.open( { windowId: chrome.windows.WINDOW_ID_CURRENT }, () => { if (chrome.runtime.lastError) { console.error( "Error opening side panel:", chrome.runtime.lastError.message ); } else { console.log("Side panel opened successfully"); } } ); } else { console.error("sidePanel permission denied"); } } ); } });
html
PreviewCollapseWrap
Copy
<!-- sidepanel.html --> <!DOCTYPE html> <html> <body> <h1>Test Side Panel</h1> <p>This is a test side panel.</p> </body> </html>

Additional Details:

  • The crash occurs consistently when using windowId: chrome.windows.WINDOW_ID_CURRENT. I have not tested with a specific tabId or dynamically retrieved windowId via chrome.windows.getCurrent.
  • The sidepanel.html file is minimal and contains no complex scripts or resources that could contribute to the crash.
  • The issue persists in both normal and incognito modes.
  • No other extensions were active during testing to rule out conflicts.
  • I have checked the Chrome crash logs (chrome://crashes), but no specific error details related to the sidePanel API were found.

Workaround Attempted:

  • I tried wrapping the chrome.sidePanel.open call in a chrome.windows.getCurrent to ensure a valid windowId:
    javascript
    CollapseWrapRun
    Copy
    chrome.windows.getCurrent((window) => { if (window && window.id) { chrome.sidePanel.open({ windowId: window.id }, () => { if (chrome.runtime.lastError) { console.error("Error:", chrome.runtime.lastError.message); } }); } else { console.error("Failed to get current window ID"); } });
    However, the crash still occurs.


----------------------------

The information contained in this email and any files transmitted with it are confidential and may be legally privileged and protected by law. It is intended solely for the use of the individual or entity to whom they are addressed (or meant to be addressed to). If you are not the intended recipient or their agent, be advised that you have received this email in error and that any review, use, dissemination, forwarding, printing, copying, or storage of this email or any action in reliance upon it, is strictly prohibited and unlawful. If you have received this email in error please notify the sender immediately and permanently delete all copies of this email and any attachments contained therein from all computers.

-----------------------------

This email, including all its attachments, is confidential and sent to provide information for discussion purposes only. No recipient may treat this correspondence as constituting an invitation, offer or solicitation to purchase or subscribe to an investment contract subject to federal securities law.

-----------------------------


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/e26aec9b-d97b-4ab9-902e-8993b35dbd80n%40chromium.org.
Message has been deleted

Oliver Dunk

unread,
Jun 20, 2025, 10:07:02 AMJun 20
to Neil Zhang, Chromium Extensions
Hi Neil,

Thanks for the extra information. I was able to reproduce and I've shared some more details in https://issues.chromium.org/426412557.

In brief, it seems like there is currently an issue with registering the side panel when `sidePanel` is granted as an optional permission.

If possible, I would avoid requesting it like that for now and make it a required permission for your extension. As there is no associated permission warning, you can request this without worrying about users being asked to accept.

If you really do need this to be optional, a workaround you could use is calling `chrome.runtime.reload` after the permission is granted. This will reload your entire extension but ensure that the side panel is correctly registered.

I've also passed the bug onto the engineering team and hopefully they will be able to take a look soon.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


On Fri, Jun 20, 2025 at 2:09 PM Neil Zhang <neil....@tron.network> wrote:
hi  Oliver,
             I  use this code in the  popup.js 
async function openSidePanelSafely(options, maxRetries = 3, delay = 1000) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      // 确认权限状态
      const hasPermission = await chrome.permissions.contains({
        permissions: ['sidePanel']
      });
     
      if (!hasPermission) {
        throw new Error('SidePanel permission not available');
      }
     
      // 添加延迟
      if (i > 0) {
        await new Promise(resolve => setTimeout(resolve, delay * i));
      }
     
      await chrome.sidePanel.open(options);
      return; // 成功则退出
    } catch (error) {
      console.warn(`尝试 ${i + 1} 打开 sidePanel 失败:`, error);
     
      if (i === maxRetries - 1) {
        throw error; // 最后一次尝试失败则抛出错误
      }
    }
  }
}

async function requestAndOpenSidePanel(options) {
  try {
    // 1. 请求权限
    const granted = await chrome.permissions.request({
      permissions: ['sidePanel', 'tabs']
    });
   
    if (!granted) {
      throw new Error('权限被拒绝');
    }
   
    // 2. 等待权限状态稳定
    console.log('权限已授予,等待 API 就绪...');
    await new Promise(resolve => setTimeout(resolve, 3000)); // 等待 3 秒
   
    // 3. 验证权限状态
    const hasPermission = await chrome.permissions.contains({
      permissions: ['sidePanel']
    });
   
    if (!hasPermission) {
      throw new Error('权限状态异常');
    }
   
    // 4. 安全地打开 sidePanel
    await openSidePanelSafely(options);
   
  } catch (error) {
    console.error('打开 sidePanel 失败:', error);
   
    // 可以提示用户重新加载扩展
    console.log('建议重新加载扩展或重启浏览器');
  }
}

when granted is true,  this code  await chrome.sidePanel.open(options) run, the chrome crash in  chrome version 137.0.7151.120  , I confirm that it is necessary ,can you check it again ,thanks you very much.


Oliver Dunk <olive...@google.com> 于2025年6月20日周五 19:35写道:


--

Neil zhang

Development Engineer 

neil.zhang@tron.network


Tron Network Ltd.    |    tron.network    |    trondao.org

The information contained in this email and any files transmitted with it are confidential and may be legally privileged and protected by law. It is intended solely for the use of the individual or entity to whom they are addressed (or meant to be addressed to). If you are not the intended recipient or their agent, be advised that you have received this email in error and that any review, use, dissemination, forwarding, printing, copying, or storage of this email or any action in reliance upon it, is strictly prohibited and unlawful. If you have received this email in error please notify the sender immediately and permanently delete all copies of this email and any attachments contained therein from all computers.
-----------------------------------------------------------------------------------------------------------

This email, including all its attachments, is confidential and sent to provide information for discussion purposes only. No recipient may treat this correspondence as constituting an invitation, offer or solicitation to purchase or subscribe to an investment contract subject to federal securities law.
------------------------------------------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages