untiktok-api 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.iframe_contentWindow = void 0;
4
- exports.iframe_contentWindow = `
5
- try {
6
- const getContentWindowProxy = {
7
- apply: function(target, ctx, args) {
8
- const iframe = args[0]
9
- if (!iframe || iframe.nodeName !== 'IFRAME') { return utils.cache.Reflect.apply(target, ctx, args) }
10
- const win = utils.cache.Reflect.apply(target, ctx, args)
11
- win.Object = window.Object
12
- win.Reflect = window.Reflect
13
- return win
14
- }
15
- }
16
- Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
17
- get() {
18
- return new Proxy(HTMLIFrameElement.prototype.contentWindow, getContentWindowProxy)
19
- }
20
- })
21
- } catch (err) { /* noop */ }
4
+ exports.iframe_contentWindow = `
5
+ try {
6
+ const getContentWindowProxy = {
7
+ apply: function(target, ctx, args) {
8
+ const iframe = args[0]
9
+ if (!iframe || iframe.nodeName !== 'IFRAME') { return utils.cache.Reflect.apply(target, ctx, args) }
10
+ const win = utils.cache.Reflect.apply(target, ctx, args)
11
+ win.Object = window.Object
12
+ win.Reflect = window.Reflect
13
+ return win
14
+ }
15
+ }
16
+ Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
17
+ get() {
18
+ return new Proxy(HTMLIFrameElement.prototype.contentWindow, getContentWindowProxy)
19
+ }
20
+ })
21
+ } catch (err) { /* noop */ }
22
22
  `;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.media_codecs = void 0;
4
- exports.media_codecs = `
5
- const makeCanPlayType = (supported, fn) => {
6
- utils.replaceWithProxy(HTMLMediaElement.prototype, 'canPlayType', {
7
- apply: function(target, ctx, args) {
8
- const type = (args || [])[0]
9
- const result = utils.cache.Reflect.apply(target, ctx, args)
10
- if (type === supported) { return 'probably' }
11
- return result
12
- }
13
- })
14
- }
15
- makeCanPlayType('video/ogg; codecs="theora"', fn => fn)
4
+ exports.media_codecs = `
5
+ const makeCanPlayType = (supported, fn) => {
6
+ utils.replaceWithProxy(HTMLMediaElement.prototype, 'canPlayType', {
7
+ apply: function(target, ctx, args) {
8
+ const type = (args || [])[0]
9
+ const result = utils.cache.Reflect.apply(target, ctx, args)
10
+ if (type === supported) { return 'probably' }
11
+ return result
12
+ }
13
+ })
14
+ }
15
+ makeCanPlayType('video/ogg; codecs="theora"', fn => fn)
16
16
  `;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.navigator_hardwareConcurrency = void 0;
4
- exports.navigator_hardwareConcurrency = `
5
- utils.replaceProperty(Object.getPrototypeOf(navigator), 'hardwareConcurrency', { get: () => opts.navigator_hardware_concurrency || 4 })
4
+ exports.navigator_hardwareConcurrency = `
5
+ utils.replaceProperty(Object.getPrototypeOf(navigator), 'hardwareConcurrency', { get: () => opts.navigator_hardware_concurrency || 4 })
6
6
  `;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.navigator_languages = void 0;
4
- exports.navigator_languages = `
5
- utils.replaceProperty(Object.getPrototypeOf(navigator), 'languages', { get: () => opts.languages || ['en-US', 'en'] })
4
+ exports.navigator_languages = `
5
+ utils.replaceProperty(Object.getPrototypeOf(navigator), 'languages', { get: () => opts.languages || ['en-US', 'en'] })
6
6
  `;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.navigator_permissions = void 0;
4
- exports.navigator_permissions = `
5
- const originalQuery = window.navigator.permissions.query
6
- window.navigator.permissions.__proto__.query = parameters =>
7
- parameters.name === 'notifications'
8
- ? Promise.resolve({ state: Notification.permission })
9
- : originalQuery(parameters)
10
- utils.patchToString(window.navigator.permissions.__proto__.query)
4
+ exports.navigator_permissions = `
5
+ const originalQuery = window.navigator.permissions.query
6
+ window.navigator.permissions.__proto__.query = parameters =>
7
+ parameters.name === 'notifications'
8
+ ? Promise.resolve({ state: Notification.permission })
9
+ : originalQuery(parameters)
10
+ utils.patchToString(window.navigator.permissions.__proto__.query)
11
11
  `;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.navigator_platform = void 0;
4
- exports.navigator_platform = `
5
- if (opts.navigator_platform) {
6
- utils.replaceProperty(Object.getPrototypeOf(navigator), 'platform', { get: () => opts.navigator_platform })
7
- }
4
+ exports.navigator_platform = `
5
+ if (opts.navigator_platform) {
6
+ utils.replaceProperty(Object.getPrototypeOf(navigator), 'platform', { get: () => opts.navigator_platform })
7
+ }
8
8
  `;
@@ -1,37 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.navigator_plugins_script = void 0;
4
- exports.navigator_plugins_script = `
5
- const data = {
6
- mimeTypes: [
7
- { type: 'application/pdf', suffixes: 'pdf', description: '', __pluginName: 'Chrome PDF Viewer' },
8
- { type: 'application/x-google-chrome-pdf', suffixes: 'pdf', description: 'Portable Document Format', __pluginName: 'Chrome PDF Plugin' },
9
- { type: 'application/x-nacl', suffixes: '', description: 'Native Client Executable', __pluginName: 'Native Client' },
10
- { type: 'application/x-pnacl', suffixes: '', description: 'Portable Native Client Executable', __pluginName: 'Native Client' }
11
- ],
12
- plugins: [
13
- { name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format', __mimeTypes: ['application/x-google-chrome-pdf'] },
14
- { name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '', __mimeTypes: ['application/pdf'] },
15
- { name: 'Native Client', filename: 'internal-nacl-plugin', description: '', __mimeTypes: ['application/x-nacl', 'application/x-pnacl'] }
16
- ]
17
- }
18
- const hasPlugins = 'plugins' in navigator && navigator.plugins.length
19
- if (!hasPlugins) {
20
- const mimeTypes = generateMagicArray(data.mimeTypes, MimeTypeArray.prototype, MimeType.prototype, 'type')
21
- const plugins = generateMagicArray(data.plugins, PluginArray.prototype, Plugin.prototype, 'name')
22
- for (const pluginData of data.plugins) {
23
- pluginData.__mimeTypes.forEach((type, index) => {
24
- plugins[pluginData.name][index] = mimeTypes[type]
25
- plugins[type] = mimeTypes[type]
26
- Object.defineProperty(mimeTypes[type], 'enabledPlugin', {
27
- value: JSON.parse(JSON.stringify(plugins[pluginData.name])),
28
- writable: false, enumerable: false, configurable: false
29
- })
30
- })
31
- }
32
- const patchNavigator = (name, value) =>
33
- utils.replaceProperty(Object.getPrototypeOf(navigator), name, { get() { return value } })
34
- patchNavigator('mimeTypes', mimeTypes)
35
- patchNavigator('plugins', plugins)
36
- }
4
+ exports.navigator_plugins_script = `
5
+ const data = {
6
+ mimeTypes: [
7
+ { type: 'application/pdf', suffixes: 'pdf', description: '', __pluginName: 'Chrome PDF Viewer' },
8
+ { type: 'application/x-google-chrome-pdf', suffixes: 'pdf', description: 'Portable Document Format', __pluginName: 'Chrome PDF Plugin' },
9
+ { type: 'application/x-nacl', suffixes: '', description: 'Native Client Executable', __pluginName: 'Native Client' },
10
+ { type: 'application/x-pnacl', suffixes: '', description: 'Portable Native Client Executable', __pluginName: 'Native Client' }
11
+ ],
12
+ plugins: [
13
+ { name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format', __mimeTypes: ['application/x-google-chrome-pdf'] },
14
+ { name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '', __mimeTypes: ['application/pdf'] },
15
+ { name: 'Native Client', filename: 'internal-nacl-plugin', description: '', __mimeTypes: ['application/x-nacl', 'application/x-pnacl'] }
16
+ ]
17
+ }
18
+ const hasPlugins = 'plugins' in navigator && navigator.plugins.length
19
+ if (!hasPlugins) {
20
+ const mimeTypes = generateMagicArray(data.mimeTypes, MimeTypeArray.prototype, MimeType.prototype, 'type')
21
+ const plugins = generateMagicArray(data.plugins, PluginArray.prototype, Plugin.prototype, 'name')
22
+ for (const pluginData of data.plugins) {
23
+ pluginData.__mimeTypes.forEach((type, index) => {
24
+ plugins[pluginData.name][index] = mimeTypes[type]
25
+ plugins[type] = mimeTypes[type]
26
+ Object.defineProperty(mimeTypes[type], 'enabledPlugin', {
27
+ value: JSON.parse(JSON.stringify(plugins[pluginData.name])),
28
+ writable: false, enumerable: false, configurable: false
29
+ })
30
+ })
31
+ }
32
+ const patchNavigator = (name, value) =>
33
+ utils.replaceProperty(Object.getPrototypeOf(navigator), name, { get() { return value } })
34
+ patchNavigator('mimeTypes', mimeTypes)
35
+ patchNavigator('plugins', plugins)
36
+ }
37
37
  `;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.navigator_userAgent_script = void 0;
4
- exports.navigator_userAgent_script = `
5
- if (opts.navigator_user_agent) {
6
- utils.replaceProperty(Object.getPrototypeOf(navigator), 'userAgent', { get: () => opts.navigator_user_agent })
7
- }
4
+ exports.navigator_userAgent_script = `
5
+ if (opts.navigator_user_agent) {
6
+ utils.replaceProperty(Object.getPrototypeOf(navigator), 'userAgent', { get: () => opts.navigator_user_agent })
7
+ }
8
8
  `;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.navigator_vendor_script = void 0;
4
- exports.navigator_vendor_script = `
5
- utils.replaceProperty(Object.getPrototypeOf(navigator), 'vendor', { get: () => opts.navigator_vendor || 'Google Inc.' })
4
+ exports.navigator_vendor_script = `
5
+ utils.replaceProperty(Object.getPrototypeOf(navigator), 'vendor', { get: () => opts.navigator_vendor || 'Google Inc.' })
6
6
  `;
@@ -1 +1 @@
1
- export declare const utils_script = "\nconst utils = {}\nutils.stripProxyFromErrors = (handler = {}) => {\n const newHandler = {}\n const traps = Object.getOwnPropertyNames(handler)\n traps.forEach(trap => {\n newHandler[trap] = function() {\n try { return handler[trap].apply(this, arguments || []) } catch (err) {\n if (!err || !err.stack || !err.stack.includes('at ')) { throw err }\n const stripWithBlacklist = stack => {\n const blacklist = ['at Reflect.' + trap + ' ', 'at Object.' + trap + ' ', 'at Object.newHandler.<computed> [as ' + trap + '] ']\n return err.stack.split('\\n').filter((line, index) => index !== 1).filter(line => !blacklist.some(bl => line.trim().startsWith(bl))).join('\\n')\n }\n const stripWithAnchor = stack => {\n const stackArr = stack.split('\\n')\n const anchor = 'at Object.newHandler.<computed> [as ' + trap + '] '\n const anchorIndex = stackArr.findIndex(line => line.trim().startsWith(anchor))\n if (anchorIndex === -1) return false\n stackArr.splice(1, anchorIndex)\n return stackArr.join('\\n')\n }\n err.stack = stripWithAnchor(err.stack) || stripWithBlacklist(err.stack)\n throw err\n }\n }\n })\n return newHandler\n}\nutils.stripErrorWithAnchor = (err, anchor) => {\n const stackArr = err.stack.split('\\n')\n const anchorIndex = stackArr.findIndex(line => line.trim().startsWith(anchor))\n if (anchorIndex === -1) return err\n stackArr.splice(1, anchorIndex)\n err.stack = stackArr.join('\\n')\n return err\n}\nutils.replaceProperty = (obj, propName, descriptorOverrides = {}) => {\n return Object.defineProperty(obj, propName, { ...(Object.getOwnPropertyDescriptor(obj, propName) || {}), ...descriptorOverrides })\n}\nutils.preloadCache = () => {\n if (utils.cache) return\n utils.cache = { Reflect: { get: Reflect.get.bind(Reflect), apply: Reflect.apply.bind(Reflect) }, nativeToStringStr: Function.toString + '' }\n}\nutils.makeNativeString = (name = '') => { utils.preloadCache(); return utils.cache.nativeToStringStr.replace('toString', name || '') }\nutils.patchToString = (obj, str = '') => {\n utils.preloadCache()\n const toStringProxy = new Proxy(Function.prototype.toString, {\n apply: function(target, ctx) {\n if (ctx === Function.prototype.toString) return utils.makeNativeString('toString')\n if (ctx === obj) return str || utils.makeNativeString(obj.name)\n const hasSameProto = Object.getPrototypeOf(Function.prototype.toString).isPrototypeOf(ctx.toString)\n if (!hasSameProto) return ctx.toString()\n return target.call(ctx)\n }\n })\n utils.replaceProperty(Function.prototype, 'toString', { value: toStringProxy })\n}\nutils.patchToStringNested = (obj = {}) => { return utils.execRecursively(obj, ['function'], utils.patchToString) }\nutils.redirectToString = (proxyObj, originalObj) => {\n utils.preloadCache()\n const toStringProxy = new Proxy(Function.prototype.toString, {\n apply: function(target, ctx) {\n if (ctx === Function.prototype.toString) return utils.makeNativeString('toString')\n if (ctx === proxyObj) {\n const fallback = () => originalObj && originalObj.name ? utils.makeNativeString(originalObj.name) : utils.makeNativeString(proxyObj.name)\n return originalObj + '' || fallback()\n }\n const hasSameProto = Object.getPrototypeOf(Function.prototype.toString).isPrototypeOf(ctx.toString)\n if (!hasSameProto) return ctx.toString()\n return target.call(ctx)\n }\n })\n utils.replaceProperty(Function.prototype, 'toString', { value: toStringProxy })\n}\nutils.replaceWithProxy = (obj, propName, handler) => {\n utils.preloadCache()\n const originalObj = obj[propName]\n const proxyObj = new Proxy(obj[propName], utils.stripProxyFromErrors(handler))\n utils.replaceProperty(obj, propName, { value: proxyObj })\n utils.redirectToString(proxyObj, originalObj)\n return true\n}\nutils.mockWithProxy = (obj, propName, pseudoTarget, handler) => {\n utils.preloadCache()\n const proxyObj = new Proxy(pseudoTarget, utils.stripProxyFromErrors(handler))\n utils.replaceProperty(obj, propName, { value: proxyObj })\n utils.patchToString(proxyObj)\n return true\n}\nutils.createProxy = (pseudoTarget, handler) => {\n utils.preloadCache()\n const proxyObj = new Proxy(pseudoTarget, utils.stripProxyFromErrors(handler))\n utils.patchToString(proxyObj)\n return proxyObj\n}\nutils.splitObjPath = objPath => ({\n objName: objPath.split('.').slice(0, -1).join('.'),\n propName: objPath.split('.').slice(-1)[0]\n})\nutils.replaceObjPathWithProxy = (objPath, handler) => {\n const { objName, propName } = utils.splitObjPath(objPath)\n const obj = eval(objName)\n return utils.replaceWithProxy(obj, propName, handler)\n}\nutils.execRecursively = (obj = {}, typeFilter = [], fn) => {\n function recurse(obj) {\n for (const key in obj) {\n if (obj[key] === undefined) continue\n if (obj[key] && typeof obj[key] === 'object') recurse(obj[key])\n else if (obj[key] && typeFilter.includes(typeof obj[key])) fn.call(this, obj[key])\n }\n }\n recurse(obj)\n return obj\n}\n";
1
+ export declare const utils_script = "\nconst utils = {}\nutils.stripProxyFromErrors = (handler = {}) => {\n const newHandler = {}\n const traps = Object.getOwnPropertyNames(handler)\n traps.forEach(trap => {\n newHandler[trap] = function() {\n try { return handler[trap].apply(this, arguments || []) } catch (err) {\n if (!err || !err.stack || !err.stack.includes('at ')) { throw err }\n const stripWithBlacklist = stack => {\n const blacklist = ['at Reflect.' + trap + ' ', 'at Object.' + trap + ' ', 'at Object.newHandler.<computed> [as ' + trap + '] ']\n return err.stack.split('\\n').filter((line, index) => index !== 1).filter(line => !blacklist.some(bl => line.trim().startsWith(bl))).join('\\n')\n }\n const stripWithAnchor = stack => {\n const stackArr = stack.split('\\n')\n const anchor = 'at Object.newHandler.<computed> [as ' + trap + '] '\n const anchorIndex = stackArr.findIndex(line => line.trim().startsWith(anchor))\n if (anchorIndex === -1) return false\n stackArr.splice(1, anchorIndex)\n return stackArr.join('\\n')\n }\n err.stack = stripWithAnchor(err.stack) || stripWithBlacklist(err.stack)\n throw err\n }\n }\n })\n return newHandler\n}\nutils.stripErrorWithAnchor = (err, anchor) => {\n const stackArr = err.stack.split('\\n')\n const anchorIndex = stackArr.findIndex(line => line.trim().startsWith(anchor))\n if (anchorIndex === -1) return err\n stackArr.splice(1, anchorIndex)\n err.stack = stackArr.join('\\n')\n return err\n}\nutils.replaceProperty = (obj, propName, descriptorOverrides = {}) => {\n return Object.defineProperty(obj, propName, { ...(Object.getOwnPropertyDescriptor(obj, propName) || {}), ...descriptorOverrides })\n}\nutils.preloadCache = () => {\n if (utils.cache) return\n utils.cache = { Reflect: { get: Reflect.get.bind(Reflect), apply: Reflect.apply.bind(Reflect) }, nativeToStringStr: Function.toString + '' }\n}\nutils.makeNativeString = (name = '') => { utils.preloadCache(); return utils.cache.nativeToStringStr.replace('toString', name || '') }\nutils.patchToString = (obj, str = '') => {\n utils.preloadCache()\n const toStringProxy = new Proxy(Function.prototype.toString, {\n apply: function(target, ctx) {\n if (ctx === Function.prototype.toString) return utils.makeNativeString('toString')\n if (ctx === obj) return str || utils.makeNativeString(obj.name)\n const hasSameProto = Object.getPrototypeOf(Function.prototype.toString).isPrototypeOf(ctx.toString)\n if (!hasSameProto) return ctx.toString()\n return target.call(ctx)\n }\n })\n utils.replaceProperty(Function.prototype, 'toString', { value: toStringProxy })\n}\nutils.patchToStringNested = (obj = {}) => { return utils.execRecursively(obj, ['function'], utils.patchToString) }\nutils.redirectToString = (proxyObj, originalObj) => {\n utils.preloadCache()\n const toStringProxy = new Proxy(Function.prototype.toString, {\n apply: function(target, ctx) {\n if (ctx === Function.prototype.toString) return utils.makeNativeString('toString')\n if (ctx === proxyObj) {\n const fallback = () => originalObj && originalObj.name ? utils.makeNativeString(originalObj.name) : utils.makeNativeString(proxyObj.name)\n return originalObj + '' || fallback()\n }\n const hasSameProto = Object.getPrototypeOf(Function.prototype.toString).isPrototypeOf(ctx.toString)\n if (!hasSameProto) return ctx.toString()\n return target.call(ctx)\n }\n })\n utils.replaceProperty(Function.prototype, 'toString', { value: toStringProxy })\n}\nutils.replaceWithProxy = (obj, propName, handler) => {\n utils.preloadCache()\n const originalObj = obj[propName]\n const proxyObj = new Proxy(obj[propName], utils.stripProxyFromErrors(handler))\n utils.replaceProperty(obj, propName, { value: proxyObj })\n utils.redirectToString(proxyObj, originalObj)\n return true\n}\nutils.mockWithProxy = (obj, propName, pseudoTarget, handler) => {\n utils.preloadCache()\n const proxyObj = new Proxy(pseudoTarget, utils.stripProxyFromErrors(handler))\n utils.replaceProperty(obj, propName, { value: proxyObj })\n utils.patchToString(proxyObj)\n return true\n}\nutils.createProxy = (pseudoTarget, handler) => {\n utils.preloadCache()\n const proxyObj = new Proxy(pseudoTarget, utils.stripProxyFromErrors(handler))\n utils.patchToString(proxyObj)\n return proxyObj\n}\nutils.splitObjPath = objPath => ({\n objName: objPath.split('.').slice(0, -1).join('.'),\n propName: objPath.split('.').slice(-1)[0]\n})\nutils.replaceObjPathWithProxy = (objPath, handler) => {\n const { objName, propName } = utils.splitObjPath(objPath)\n const obj = objName.split('.').reduce((o, i) => o ? o[i] : undefined, window)\n return utils.replaceWithProxy(obj, propName, handler)\n}\nutils.execRecursively = (obj = {}, typeFilter = [], fn) => {\n function recurse(obj) {\n for (const key in obj) {\n if (obj[key] === undefined) continue\n if (obj[key] && typeof obj[key] === 'object') recurse(obj[key])\n else if (obj[key] && typeFilter.includes(typeof obj[key])) fn.call(this, obj[key])\n }\n }\n recurse(obj)\n return obj\n}\n";
@@ -1,119 +1,119 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.utils_script = void 0;
4
- exports.utils_script = `
5
- const utils = {}
6
- utils.stripProxyFromErrors = (handler = {}) => {
7
- const newHandler = {}
8
- const traps = Object.getOwnPropertyNames(handler)
9
- traps.forEach(trap => {
10
- newHandler[trap] = function() {
11
- try { return handler[trap].apply(this, arguments || []) } catch (err) {
12
- if (!err || !err.stack || !err.stack.includes('at ')) { throw err }
13
- const stripWithBlacklist = stack => {
14
- const blacklist = ['at Reflect.' + trap + ' ', 'at Object.' + trap + ' ', 'at Object.newHandler.<computed> [as ' + trap + '] ']
15
- return err.stack.split('\\n').filter((line, index) => index !== 1).filter(line => !blacklist.some(bl => line.trim().startsWith(bl))).join('\\n')
16
- }
17
- const stripWithAnchor = stack => {
18
- const stackArr = stack.split('\\n')
19
- const anchor = 'at Object.newHandler.<computed> [as ' + trap + '] '
20
- const anchorIndex = stackArr.findIndex(line => line.trim().startsWith(anchor))
21
- if (anchorIndex === -1) return false
22
- stackArr.splice(1, anchorIndex)
23
- return stackArr.join('\\n')
24
- }
25
- err.stack = stripWithAnchor(err.stack) || stripWithBlacklist(err.stack)
26
- throw err
27
- }
28
- }
29
- })
30
- return newHandler
31
- }
32
- utils.stripErrorWithAnchor = (err, anchor) => {
33
- const stackArr = err.stack.split('\\n')
34
- const anchorIndex = stackArr.findIndex(line => line.trim().startsWith(anchor))
35
- if (anchorIndex === -1) return err
36
- stackArr.splice(1, anchorIndex)
37
- err.stack = stackArr.join('\\n')
38
- return err
39
- }
40
- utils.replaceProperty = (obj, propName, descriptorOverrides = {}) => {
41
- return Object.defineProperty(obj, propName, { ...(Object.getOwnPropertyDescriptor(obj, propName) || {}), ...descriptorOverrides })
42
- }
43
- utils.preloadCache = () => {
44
- if (utils.cache) return
45
- utils.cache = { Reflect: { get: Reflect.get.bind(Reflect), apply: Reflect.apply.bind(Reflect) }, nativeToStringStr: Function.toString + '' }
46
- }
47
- utils.makeNativeString = (name = '') => { utils.preloadCache(); return utils.cache.nativeToStringStr.replace('toString', name || '') }
48
- utils.patchToString = (obj, str = '') => {
49
- utils.preloadCache()
50
- const toStringProxy = new Proxy(Function.prototype.toString, {
51
- apply: function(target, ctx) {
52
- if (ctx === Function.prototype.toString) return utils.makeNativeString('toString')
53
- if (ctx === obj) return str || utils.makeNativeString(obj.name)
54
- const hasSameProto = Object.getPrototypeOf(Function.prototype.toString).isPrototypeOf(ctx.toString)
55
- if (!hasSameProto) return ctx.toString()
56
- return target.call(ctx)
57
- }
58
- })
59
- utils.replaceProperty(Function.prototype, 'toString', { value: toStringProxy })
60
- }
61
- utils.patchToStringNested = (obj = {}) => { return utils.execRecursively(obj, ['function'], utils.patchToString) }
62
- utils.redirectToString = (proxyObj, originalObj) => {
63
- utils.preloadCache()
64
- const toStringProxy = new Proxy(Function.prototype.toString, {
65
- apply: function(target, ctx) {
66
- if (ctx === Function.prototype.toString) return utils.makeNativeString('toString')
67
- if (ctx === proxyObj) {
68
- const fallback = () => originalObj && originalObj.name ? utils.makeNativeString(originalObj.name) : utils.makeNativeString(proxyObj.name)
69
- return originalObj + '' || fallback()
70
- }
71
- const hasSameProto = Object.getPrototypeOf(Function.prototype.toString).isPrototypeOf(ctx.toString)
72
- if (!hasSameProto) return ctx.toString()
73
- return target.call(ctx)
74
- }
75
- })
76
- utils.replaceProperty(Function.prototype, 'toString', { value: toStringProxy })
77
- }
78
- utils.replaceWithProxy = (obj, propName, handler) => {
79
- utils.preloadCache()
80
- const originalObj = obj[propName]
81
- const proxyObj = new Proxy(obj[propName], utils.stripProxyFromErrors(handler))
82
- utils.replaceProperty(obj, propName, { value: proxyObj })
83
- utils.redirectToString(proxyObj, originalObj)
84
- return true
85
- }
86
- utils.mockWithProxy = (obj, propName, pseudoTarget, handler) => {
87
- utils.preloadCache()
88
- const proxyObj = new Proxy(pseudoTarget, utils.stripProxyFromErrors(handler))
89
- utils.replaceProperty(obj, propName, { value: proxyObj })
90
- utils.patchToString(proxyObj)
91
- return true
92
- }
93
- utils.createProxy = (pseudoTarget, handler) => {
94
- utils.preloadCache()
95
- const proxyObj = new Proxy(pseudoTarget, utils.stripProxyFromErrors(handler))
96
- utils.patchToString(proxyObj)
97
- return proxyObj
98
- }
99
- utils.splitObjPath = objPath => ({
100
- objName: objPath.split('.').slice(0, -1).join('.'),
101
- propName: objPath.split('.').slice(-1)[0]
102
- })
103
- utils.replaceObjPathWithProxy = (objPath, handler) => {
104
- const { objName, propName } = utils.splitObjPath(objPath)
105
- const obj = eval(objName)
106
- return utils.replaceWithProxy(obj, propName, handler)
107
- }
108
- utils.execRecursively = (obj = {}, typeFilter = [], fn) => {
109
- function recurse(obj) {
110
- for (const key in obj) {
111
- if (obj[key] === undefined) continue
112
- if (obj[key] && typeof obj[key] === 'object') recurse(obj[key])
113
- else if (obj[key] && typeFilter.includes(typeof obj[key])) fn.call(this, obj[key])
114
- }
115
- }
116
- recurse(obj)
117
- return obj
118
- }
4
+ exports.utils_script = `
5
+ const utils = {}
6
+ utils.stripProxyFromErrors = (handler = {}) => {
7
+ const newHandler = {}
8
+ const traps = Object.getOwnPropertyNames(handler)
9
+ traps.forEach(trap => {
10
+ newHandler[trap] = function() {
11
+ try { return handler[trap].apply(this, arguments || []) } catch (err) {
12
+ if (!err || !err.stack || !err.stack.includes('at ')) { throw err }
13
+ const stripWithBlacklist = stack => {
14
+ const blacklist = ['at Reflect.' + trap + ' ', 'at Object.' + trap + ' ', 'at Object.newHandler.<computed> [as ' + trap + '] ']
15
+ return err.stack.split('\\n').filter((line, index) => index !== 1).filter(line => !blacklist.some(bl => line.trim().startsWith(bl))).join('\\n')
16
+ }
17
+ const stripWithAnchor = stack => {
18
+ const stackArr = stack.split('\\n')
19
+ const anchor = 'at Object.newHandler.<computed> [as ' + trap + '] '
20
+ const anchorIndex = stackArr.findIndex(line => line.trim().startsWith(anchor))
21
+ if (anchorIndex === -1) return false
22
+ stackArr.splice(1, anchorIndex)
23
+ return stackArr.join('\\n')
24
+ }
25
+ err.stack = stripWithAnchor(err.stack) || stripWithBlacklist(err.stack)
26
+ throw err
27
+ }
28
+ }
29
+ })
30
+ return newHandler
31
+ }
32
+ utils.stripErrorWithAnchor = (err, anchor) => {
33
+ const stackArr = err.stack.split('\\n')
34
+ const anchorIndex = stackArr.findIndex(line => line.trim().startsWith(anchor))
35
+ if (anchorIndex === -1) return err
36
+ stackArr.splice(1, anchorIndex)
37
+ err.stack = stackArr.join('\\n')
38
+ return err
39
+ }
40
+ utils.replaceProperty = (obj, propName, descriptorOverrides = {}) => {
41
+ return Object.defineProperty(obj, propName, { ...(Object.getOwnPropertyDescriptor(obj, propName) || {}), ...descriptorOverrides })
42
+ }
43
+ utils.preloadCache = () => {
44
+ if (utils.cache) return
45
+ utils.cache = { Reflect: { get: Reflect.get.bind(Reflect), apply: Reflect.apply.bind(Reflect) }, nativeToStringStr: Function.toString + '' }
46
+ }
47
+ utils.makeNativeString = (name = '') => { utils.preloadCache(); return utils.cache.nativeToStringStr.replace('toString', name || '') }
48
+ utils.patchToString = (obj, str = '') => {
49
+ utils.preloadCache()
50
+ const toStringProxy = new Proxy(Function.prototype.toString, {
51
+ apply: function(target, ctx) {
52
+ if (ctx === Function.prototype.toString) return utils.makeNativeString('toString')
53
+ if (ctx === obj) return str || utils.makeNativeString(obj.name)
54
+ const hasSameProto = Object.getPrototypeOf(Function.prototype.toString).isPrototypeOf(ctx.toString)
55
+ if (!hasSameProto) return ctx.toString()
56
+ return target.call(ctx)
57
+ }
58
+ })
59
+ utils.replaceProperty(Function.prototype, 'toString', { value: toStringProxy })
60
+ }
61
+ utils.patchToStringNested = (obj = {}) => { return utils.execRecursively(obj, ['function'], utils.patchToString) }
62
+ utils.redirectToString = (proxyObj, originalObj) => {
63
+ utils.preloadCache()
64
+ const toStringProxy = new Proxy(Function.prototype.toString, {
65
+ apply: function(target, ctx) {
66
+ if (ctx === Function.prototype.toString) return utils.makeNativeString('toString')
67
+ if (ctx === proxyObj) {
68
+ const fallback = () => originalObj && originalObj.name ? utils.makeNativeString(originalObj.name) : utils.makeNativeString(proxyObj.name)
69
+ return originalObj + '' || fallback()
70
+ }
71
+ const hasSameProto = Object.getPrototypeOf(Function.prototype.toString).isPrototypeOf(ctx.toString)
72
+ if (!hasSameProto) return ctx.toString()
73
+ return target.call(ctx)
74
+ }
75
+ })
76
+ utils.replaceProperty(Function.prototype, 'toString', { value: toStringProxy })
77
+ }
78
+ utils.replaceWithProxy = (obj, propName, handler) => {
79
+ utils.preloadCache()
80
+ const originalObj = obj[propName]
81
+ const proxyObj = new Proxy(obj[propName], utils.stripProxyFromErrors(handler))
82
+ utils.replaceProperty(obj, propName, { value: proxyObj })
83
+ utils.redirectToString(proxyObj, originalObj)
84
+ return true
85
+ }
86
+ utils.mockWithProxy = (obj, propName, pseudoTarget, handler) => {
87
+ utils.preloadCache()
88
+ const proxyObj = new Proxy(pseudoTarget, utils.stripProxyFromErrors(handler))
89
+ utils.replaceProperty(obj, propName, { value: proxyObj })
90
+ utils.patchToString(proxyObj)
91
+ return true
92
+ }
93
+ utils.createProxy = (pseudoTarget, handler) => {
94
+ utils.preloadCache()
95
+ const proxyObj = new Proxy(pseudoTarget, utils.stripProxyFromErrors(handler))
96
+ utils.patchToString(proxyObj)
97
+ return proxyObj
98
+ }
99
+ utils.splitObjPath = objPath => ({
100
+ objName: objPath.split('.').slice(0, -1).join('.'),
101
+ propName: objPath.split('.').slice(-1)[0]
102
+ })
103
+ utils.replaceObjPathWithProxy = (objPath, handler) => {
104
+ const { objName, propName } = utils.splitObjPath(objPath)
105
+ const obj = objName.split('.').reduce((o, i) => o ? o[i] : undefined, window)
106
+ return utils.replaceWithProxy(obj, propName, handler)
107
+ }
108
+ utils.execRecursively = (obj = {}, typeFilter = [], fn) => {
109
+ function recurse(obj) {
110
+ for (const key in obj) {
111
+ if (obj[key] === undefined) continue
112
+ if (obj[key] && typeof obj[key] === 'object') recurse(obj[key])
113
+ else if (obj[key] && typeFilter.includes(typeof obj[key])) fn.call(this, obj[key])
114
+ }
115
+ }
116
+ recurse(obj)
117
+ return obj
118
+ }
119
119
  `;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.webgl_vendor_script = void 0;
4
- exports.webgl_vendor_script = `
5
- const getParameterProxy = {
6
- apply: function(target, ctx, args) {
7
- const param = (args || [])[0]
8
- const UNMASKED_VENDOR_WEBGL = 0x9245
9
- const UNMASKED_RENDERER_WEBGL = 0x9246
10
- if (param === UNMASKED_VENDOR_WEBGL) { return opts.webgl_vendor || 'Intel Inc.' }
11
- if (param === UNMASKED_RENDERER_WEBGL) { return opts.webgl_renderer || 'Intel Iris OpenGL Engine' }
12
- return utils.cache.Reflect.apply(target, ctx, args)
13
- }
14
- }
15
- utils.replaceWithProxy(WebGLRenderingContext.prototype, 'getParameter', getParameterProxy)
4
+ exports.webgl_vendor_script = `
5
+ const getParameterProxy = {
6
+ apply: function(target, ctx, args) {
7
+ const param = (args || [])[0]
8
+ const UNMASKED_VENDOR_WEBGL = 0x9245
9
+ const UNMASKED_RENDERER_WEBGL = 0x9246
10
+ if (param === UNMASKED_VENDOR_WEBGL) { return opts.webgl_vendor || 'Intel Inc.' }
11
+ if (param === UNMASKED_RENDERER_WEBGL) { return opts.webgl_renderer || 'Intel Iris OpenGL Engine' }
12
+ return utils.cache.Reflect.apply(target, ctx, args)
13
+ }
14
+ }
15
+ utils.replaceWithProxy(WebGLRenderingContext.prototype, 'getParameter', getParameterProxy)
16
16
  `;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.window_outerdimensions = void 0;
4
- exports.window_outerdimensions = `
5
- try {
6
- if (window.outerWidth === 0) { Object.defineProperty(window, 'outerWidth', { get: () => window.innerWidth }) }
7
- if (window.outerHeight === 0) { Object.defineProperty(window, 'outerHeight', { get: () => window.innerHeight }) }
8
- } catch (err) { /* noop */ }
4
+ exports.window_outerdimensions = `
5
+ try {
6
+ if (window.outerWidth === 0) { Object.defineProperty(window, 'outerWidth', { get: () => window.innerWidth }) }
7
+ if (window.outerHeight === 0) { Object.defineProperty(window, 'outerHeight', { get: () => window.innerHeight }) }
8
+ } catch (err) { /* noop */ }
9
9
  `;
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "untiktok-api",
3
- "version": "1.0.3",
4
- "description": "Unofficial TikTok API wrapper in TypeScript (ported from Python)",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "build": "tsc -p tsconfig.build.json",
9
- "dev": "ts-node src/index.ts",
10
- "typecheck": "tsc --noEmit",
11
- "lint": "eslint src",
12
- "clean": "rimraf dist",
13
- "prepublishOnly": "npm run clean && npm run build"
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
- "keywords": [
19
- "tiktok",
20
- "api",
21
- "scraper",
22
- "typescript",
23
- "playwright"
24
- ],
25
- "author": "AlGhozaliRamadhan",
26
- "license": "MIT",
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/AlGhozaliRamadhan/UnTikTok-Api.git"
30
- },
31
- "bugs": {
32
- "url": "https://github.com/AlGhozaliRamadhan/UnTikTok-Api/issues"
33
- },
34
- "homepage": "https://github.com/AlGhozaliRamadhan/UnTikTok-Api#readme",
35
- "dependencies": {
36
- "axios": "^1.17.0",
37
- "https-proxy-agent": "^9.1.0",
38
- "playwright": "^1.44.0"
39
- },
40
- "devDependencies": {
41
- "@eslint/js": "^10.0.1",
42
- "@types/node": "^25.9.3",
43
- "eslint": "^10.5.0",
44
- "rimraf": "^6.1.3",
45
- "ts-node": "^10.9.2",
46
- "typescript": "^6.0.3",
47
- "typescript-eslint": "^8.61.0"
48
- }
49
- }
1
+ {
2
+ "name": "untiktok-api",
3
+ "version": "1.0.5",
4
+ "description": "Unofficial TikTok API wrapper in TypeScript (ported from Python)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.build.json",
9
+ "dev": "ts-node src/index.ts",
10
+ "typecheck": "tsc --noEmit",
11
+ "lint": "eslint src",
12
+ "clean": "rimraf dist",
13
+ "prepublishOnly": "npm run clean && npm run build"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "tiktok",
20
+ "api",
21
+ "scraper",
22
+ "typescript",
23
+ "playwright"
24
+ ],
25
+ "author": "AlGhozaliRamadhan",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/AlGhozaliRamadhan/UnTikTok-Api.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/AlGhozaliRamadhan/UnTikTok-Api/issues"
33
+ },
34
+ "homepage": "https://github.com/AlGhozaliRamadhan/UnTikTok-Api#readme",
35
+ "dependencies": {
36
+ "axios": "^1.17.0",
37
+ "https-proxy-agent": "^9.1.0",
38
+ "playwright": "^1.44.0"
39
+ },
40
+ "devDependencies": {
41
+ "@eslint/js": "^10.0.1",
42
+ "@types/node": "^25.9.3",
43
+ "eslint": "^10.5.0",
44
+ "rimraf": "^6.1.3",
45
+ "ts-node": "^10.9.2",
46
+ "typescript": "^6.0.3",
47
+ "typescript-eslint": "^8.61.0"
48
+ }
49
+ }