Hello,
I created an extension that amongst other things opens Google search results in the sidebar. However, the search results are truncated and do not fit (i.e. the lines don’t wrap) within the width of the sidebar.
I tried to correct this by specifying a mobile user agent in the web request, but it doesn’t do anything:
/// Add a mobile header to outgoing requests
browser.webRequest.onBeforeSendHeaders.addListener(
rewriteUserAgentHeader,
requestFilter,
["blocking", "requestHeaders"]
);
/*
Rewrite the User-Agent header to contextsearch_userAgent
*/
function rewriteUserAgentHeader(e) {
if (!contextsearch_openSearchResultsInSidebar) {
return {};
}
for (const header of e.requestHeaders) {
if (header.name.toLowerCase() === "user-agent") {
header.value = contextsearch_userAgent;
}
}
return { requestHeaders: e.requestHeaders };
}
I also tried setting the viewport width using a solution proposed by chatGPT, but that generated an error as it seems that width was not recognised:
// Get the current active tab
browser. tabs. query({active: true,
currentWindow: true}).then(tabs => {
const activeTab = tabs[0];
// Open the Google search results in a
sidebar with modified viewport size
browser.sidebarAction.open({
url: "https://www.google.com/search?
q=${activeTab.title}',
tabId: activeTab.id
});
/ Modify the viewport size of the sidebar
browser.sidebarAction.setPanel({
width: 360,
height: 640
});
});
I would be most grateful if anyone could help fix this problem.
Thank you.