Skip to content

Commit

Permalink
Set User-Agent header to GlobalContext.userAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
shawwn committed Jun 26, 2019
1 parent 988072a commit 58ff970
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 8 deletions.
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
4 changes: 2 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 = GlobalContext.userAgent;
this.vendor = 'Exokit';
this.platform = os.platform();
this.hardwareConcurrency = os.cpus().length;
Expand All @@ -89,4 +89,4 @@ class Navigator {
return getGamepads();
}
}
module.exports.Navigator = Navigator;
module.exports.Navigator = Navigator;
1 change: 1 addition & 0 deletions src/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const {
GlobalContext.id = id;
GlobalContext.args = args;
GlobalContext.version = version;
GlobalContext.userAgent = `Mozilla/5.0 (OS) AppleWebKit/999.0 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/999.0 Exokit/${GlobalContext.version}`;

const {_parseDocument, _parseDocumentAst, getBoundDocumentElements, DocumentType, DOMImplementation, initDocument} = require('./Document');
const {
Expand Down
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 GlobalContext = require('./GlobalContext');
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', GlobalContext.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

0 comments on commit 58ff970

Please sign in to comment.