allow setting blank UA using 'empty' keyword
This commit is contained in:
parent
166e756a45
commit
e51d174079
2 changed files with 10 additions and 6 deletions
14
common.js
14
common.js
|
@ -199,7 +199,7 @@ var onBeforeSendHeaders = ({tabId, url, requestHeaders, type}) => {
|
|||
if (str) {
|
||||
for (let i = 0, name = requestHeaders[0].name; i < requestHeaders.length; i += 1, name = requestHeaders[i].name) {
|
||||
if (name === 'User-Agent' || name === 'user-agent') {
|
||||
requestHeaders[i].value = str;
|
||||
requestHeaders[i].value = str === 'empty' ? '' : str;
|
||||
return {
|
||||
requestHeaders
|
||||
};
|
||||
|
@ -215,16 +215,20 @@ var onCommitted = ({frameId, url, tabId}) => {
|
|||
}
|
||||
const o = cache[tabId] || ua.object(tabId);
|
||||
if (o.userAgent) {
|
||||
let {userAgent, appVersion, platform, vendor} = o;
|
||||
if (o.userAgent === 'empty') {
|
||||
userAgent = appVersion = platform = vendor = '';
|
||||
}
|
||||
chrome.tabs.executeScript(tabId, {
|
||||
runAt: 'document_start',
|
||||
frameId,
|
||||
code: `{
|
||||
const script = document.createElement('script');
|
||||
script.textContent = \`{
|
||||
navigator.__defineGetter__('userAgent', () => '${o.userAgent}');
|
||||
navigator.__defineGetter__('appVersion', () => '${o.appVersion}');
|
||||
navigator.__defineGetter__('platform', () => '${o.platform}');
|
||||
navigator.__defineGetter__('vendor', () => '${o.vendor}');
|
||||
navigator.__defineGetter__('userAgent', () => '${userAgent}');
|
||||
navigator.__defineGetter__('appVersion', () => '${appVersion}');
|
||||
navigator.__defineGetter__('platform', () => '${platform}');
|
||||
navigator.__defineGetter__('vendor', () => '${vendor}');
|
||||
}\`;
|
||||
document.documentElement.appendChild(script);
|
||||
script.remove();
|
||||
|
|
|
@ -158,7 +158,7 @@
|
|||
<input type="button" value="Window" title="Set this string as this window's User-Agent string" data-cmd="window">
|
||||
<input type="button" value="Reset" title="Reset User-Agent string to the default one. This will not reset window-based UA strings. To reset them, use the 'Restart' button" style="margin-left: 2px;" data-cmd="reset">
|
||||
</div>
|
||||
<input id="ua" type="text" placeholder="Your preferred user-agent string">
|
||||
<input id="ua" type="text" placeholder="Your preferred user-agent string" title="To set blank user-agent string, use 'empty' keyword">
|
||||
<div id="explore"></div>
|
||||
<script src="ua-parser.min.js"></script>
|
||||
<script src="index.js"></script>
|
||||
|
|
Loading…
Reference in a new issue