Reputation: 4657
I have a chrome extension to show the Google Translate easier to the user. There is an option if user wants to see the translate in a new windows or not. To showing the translate page in a new windows I want to show the user a compact translate page. I want to change USER-AGENT to show the user Google Translate's mobile version.
I tried this and this is my function to open the new windows but the windows's user agent doesn't change and I don't know how can I resolve the problem:
function OpenURL(url, tab)
{
if(config.tab=="true")
{
var id = tab.index +1;
chrome.tabs.create({'url': url, 'index': id});
}
else
{
chrome.webRequest.onBeforeSendHeaders.addListener(
function(info) {
// Replace the User-Agent header
var headers = info.requestHeaders;
headers.forEach(function(header, i) {
if (header.name.toLowerCase() == 'user-agent') {
header.value = 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10';
}
});
return {requestHeaders: headers};
},
// Request filter
{
// Modify the headers for these pages
urls: [
"*translate.google.com*",
],
// In the main window and frames
types: ["main_frame", "sub_frame"]
},
["blocking", "requestHeaders"]
);
newwindow = window.open(url, "_blank", "resizable=yes, scrollbars=yes, titlebar=yes");
}
}
Can anyone Help me?
Upvotes: 0
Views: 1068
Reputation: 349032
"*translate.google.com*",
is an invalid match pattern, try
"*://translate.google.com/*"
instead.
Upvotes: 1