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 ac36371 commit 5b27f89
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 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
3 changes: 2 additions & 1 deletion src/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,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 Expand Up @@ -493,7 +494,7 @@ const _makeRequestAnimationFrame = window => (fn, priority = 0) => {
}
}
window.navigator = {
userAgent: `Mozilla/5.0 (OS) AppleWebKit/999.0 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/999.0 Exokit/${GlobalContext.version}`,
userAgent: GlobalContext.userAgent,
vendor: 'Exokit',
platform: os.platform(),
hardwareConcurrency: os.cpus().length,
Expand Down
7 changes: 1 addition & 6 deletions src/WindowBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
const {CustomEvent, DragEvent, ErrorEvent, Event, EventTarget, KeyboardEvent, MessageEvent, MouseEvent, WheelEvent, PromiseRejectionEvent} = require('./Event');
const {FileReader} = require('./File.js');
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 @@ -149,11 +149,6 @@ class Worker extends EventTarget {
self.URL = URL;

self.fetch = (u, options) => {
const o = Object.assign({}, options || {});
const h = (o.headers instanceof Headers) ? o.headers : new Headers(o.headers);
h.set('User-Agent', self.navigator.userAgent);
o.headers = h;
options = o;
if (typeof u === 'string') {
const blob = URL.lookupObjectURL(u);
if (blob) {
Expand Down
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 5b27f89

Please sign in to comment.