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:
- Create a Chrome extension with Manifest V3 and include the sidePanel permission in optional_permissions in manifest.json.
- Load the extension in Chrome using the "Load unpacked" option.
- Trigger a dynamic permission request for sidePanel using chrome.permissions.request.
- After the permission is granted, call chrome.sidePanel.open({ windowId: chrome.windows.WINDOW_ID_CURRENT }) to open the side panel.
- 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:
jsonCollapseWrapCopy// 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" } }javascriptCollapseWrapRunCopy// 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"); } } ); } });htmlPreviewCollapseWrapCopy<!-- 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:
However, the crash still occurs.javascriptCollapseWrapRunCopychrome.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"); } });
----------------------------
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.
hi Oliver,I use this code in the popup.jsasync 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写道:
--
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.
------------------------------------------------------------------------------------------------------------