Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set User-Agent header to window.navigator.userAgent #1373

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const he = require('he');
const parse5 = require('parse5');
const parseIntStrict = require('parse-int');
const selector = require('window-selector');
const fetch = require('window-fetch');
const fetch = require('./fetch');
const {Blob} = fetch;
const htmlUnescape = require('unescape');

Expand Down
7 changes: 5 additions & 2 deletions src/Navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports.Clipboard = Clipboard;

class Navigator {
constructor() {
this.userAgent = `Mozilla/5.0 (OS) AppleWebKit/999.0 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/999.0 Exokit/${GlobalContext.version}`;
this.userAgent = Navigator.userAgent;
this.vendor = 'Exokit';
this.platform = os.platform();
this.hardwareConcurrency = os.cpus().length;
Expand All @@ -82,11 +82,14 @@ class Navigator {
this.clipboard = new Clipboard();
this.webkitGetUserMedia = getUserMedia; // for feature detection
}
static get userAgent() {
return `Mozilla/5.0 (OS) AppleWebKit/999.0 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/999.0 Exokit/${GlobalContext.version}`
}
getVRDisplaysSync() {
return getHMDType() ? [window[symbols.mrDisplaysSymbol].vrDisplay] : [];
}
getGamepads() {
return getGamepads();
}
}
module.exports.Navigator = Navigator;
module.exports.Navigator = Navigator;
4 changes: 2 additions & 2 deletions src/WindowBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {CustomEvent, DragEvent, ErrorEvent, Event, EventTarget, KeyboardEvent, Me
const {MediaDevices, Clipboard, Navigator} = require('./Navigator');
const {FileReader} = require('./File');
const {XMLHttpRequest, FormData} = require('window-xhr');
const fetch = require('window-fetch');
const fetch = require('./fetch');
const {Request, Response, Headers, Blob} = fetch;
const WebSocket = require('ws/lib/websocket');

Expand Down Expand Up @@ -396,4 +396,4 @@ if (onbeforeload) {
if (!args.require) {
global.require = undefined;
}
global.process = undefined;
global.process = undefined;
2 changes: 1 addition & 1 deletion src/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
} = require('worker_threads');

const {createImageBitmap} = require('./DOM.js');
const fetch = require('window-fetch');
const fetch = require('./fetch');
const {XMLHttpRequest} = require('window-xhr');
const WebSocket = require('ws/lib/websocket');
const {FileReader} = require('./File.js');
Expand Down
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const url = require('url');
const {URL} = url;

const fetch = require('window-fetch');
const fetch = require('./fetch');
const GlobalContext = require('./GlobalContext');
const symbols = require('./symbols');
const {_getBaseUrl} = require('./utils');
Expand Down
13 changes: 13 additions & 0 deletions src/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { Navigator } = require('./Navigator');
const fetch = require('window-fetch');

Object.assign(module.exports, fetch);

module.exports = (u, options) => {
const o = Object.assign({}, options || {});
const h = (o.headers instanceof fetch.Headers) ? o.headers : new fetch.Headers(o.headers);
h.set('User-Agent', Navigator.userAgent);
o.headers = h;
return fetch(u, o);
};

2 changes: 1 addition & 1 deletion src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ consoleStream._writev = (chunks, callback) => {
};
global.console = new Console(consoleStream);

const fetch = require('window-fetch');
const fetch = require('./fetch');
const {workerData, parentPort} = require('worker_threads');
const {url, int32Array} = workerData;

Expand Down