I am not so good at JavaScript, but I wanted to try making the extension for Microsoft Edge where it'll randomly search in bing. The desktop search is working for now, but Mobile search isn't able to spoof the search as mobile device. How can I solve it? I have manifest version 3.
This is my function which search in new tab:
function executeSearchM(searches){
/*
Spoof to mobile, not working :(
*/
for(var i=0; i<searches.length; i++){
var win = window.open('https://www.bing.com/search?q='+searches[i],'_blank');
win.focus();
}
}
Search is working but it is still in Desktop mode. What should I do to spoof it as mobile device search.
This is spoof function:
function spoof(){
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name === 'User-Agent') {
details.requestHeaders.splice(i, 1);
break;
}
}
details.requestHeaders.push({name: 'User-Agent', value: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Mobile Safari/537.36'});
return {requestHeaders: details.requestHeaders};
},
{urls: ["<all_urls>"]},
["blocking", "requestHeaders"]
);
}
I tried lots of things to spoof as a device but it is not working, I am not good at JavaScript that's why I am not able to do it properly.