@fingerprint/agent 4.0.0 → 4.0.1
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.
- package/README.md +2 -2
- package/dist/fp.cjs.min.js +2 -2
- package/dist/fp.d.ts +32 -4
- package/dist/fp.esm.min.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,9 +76,9 @@ Note that you need to replace `your-pro-key` with a public API key from the [das
|
|
|
76
76
|
|
|
77
77
|
🍿 [Live demo](https://fingerprint.com/demo)
|
|
78
78
|
|
|
79
|
-
⏱ [How to upgrade from Open Source to Pro in 30 seconds](https://
|
|
79
|
+
⏱ [How to upgrade from Open Source to Pro in 30 seconds](https://docs.fingerprint.com/docs/migrating-from-fingerprintjs-to-fingerprint-pro)
|
|
80
80
|
|
|
81
|
-
⬆️ [How to migrate from Fingerprint version
|
|
81
|
+
⬆️ [How to migrate from Fingerprint version 3](https://docs.fingerprint.com/reference/migrating-from-v3-to-v4)
|
|
82
82
|
|
|
83
83
|
📕 [Fingerprint documentation](https://dev.fingerprint.com)
|
|
84
84
|
|
package/dist/fp.cjs.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Fingerprint v4.0.
|
|
2
|
+
* Fingerprint v4.0.1 - Copyright (c) FingerprintJS, Inc, 2026 (https://fingerprint.com)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t="csp_block",e="invalid_endpoint",n="script_load_fail",r="endpoints_misconfigured",o="bundle_not_defined",i={client_timeout:"Client timeout",network_connection:"Network connection error",network_abort:"Network request aborted",[t]:"Blocked by CSP",[e]:'The provided endpoint in "endpoints" parameter is not a valid URL',handle_agent_data:"Handle on demand agent data error",[n]:"Failed to load the JS script of the agent",[o]:"9319",bad_response_format:"Can't parse the backend response. Make sure the proper endpoints are used.",api_key_missing:"The `apiKey` option is not provided",api_key_invalid:"The `apiKey` option is not a string",cache_misconfigured:"The `cache` option is misconfigured",[r]:"The `endpoints` option is misconfigured",wrong_worker_option:"Wrong `worker` option, it should be a Worker instance",worker_initialization_failed:"Web Worker initialization failed",sandboxed_iframe:"Running inside sandboxed iframes is not supported"};class c extends Error{constructor(t,e){super(t),this.name="FingerprintError",this.event_id=null,this.code=e}}function a(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}const s=Symbol("withoutDefault");function u(t){return{__type__:s,value:t}}function f(t){return!!t&&t.__type__===s}function l(t){return t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function d(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}function p(t){const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>127)return(new TextEncoder).encode(t);e[n]=r}return e}function h(t){if("function"==typeof TextDecoder){const e=(new TextDecoder).decode(t);if(e)return e}const e=l(t);return decodeURIComponent(escape(String.fromCharCode.apply(null,e)))}function w(t,e){return(t-e+256)%256}function y(t){if(t instanceof Array)return t.map(y);if(t&&"object"==typeof t){const e={};for(const n of Object.keys(t))e[n]=y(t[n]);return e}return t}function m(t){return g(t)?t:[t]}const g=Array.isArray;function v(t){if(URL.prototype)try{return new URL(t,location.href),!1}catch(t){if(b(t))return!0;throw t}}function b(t){return t instanceof Error&&"TypeError"===t.name}function _(t){if(v(t))return t;const e=new URL(t);return e.search="",e.toString()}function A(t){return t.endsWith("/")?t:`${t}/`}const k="https://fpnpmcdn.net/",U=Symbol("default");function x(t,e,n=!1,r){const o=n?function(t){const{protocol:e}=t;return`${e}://${new URL(k).host}/`}(e):function(t){const{region:e,protocol:n}=t;let r=t.host;"us"!==e&&(r=`${e}.${r}`);return`${n}://${r}/`}(e);return n?function(t,e){const n="web",r=[],o=t===k?`${t}`:`${t}${n}`;if($(e))C(e.script,o,r,"script");else for(const t of E(e))T(t,[{defaultUrl:o,output:r,path:n}],!0);return{script:r}}(o,t):function(t,e,n){const r=[],o=[];if($(e))C(e.helper,t,r,"helper"),C(e.ingress,t,o,"ingress");else for(const i of E(e))n?P(R(i,t),r,n):T(i,[{defaultUrl:t,output:r}]),T(i,[{defaultUrl:t,output:o}]);return{helper:r,get:o}}(o,t,r)}function $(t){return!!t&&"object"==typeof t&&!Array.isArray(t)&&!f(t)}function C(t,e,n,r){var o;for(const i of E(t)){D(n,i===U?e:null===(o=L(i,`\`${r}\` endpoint`))||void 0===o?void 0:o.href)}}function E(t){return f(t)?m(t.value):void 0===t?[U]:[...m(t),U]}function D(t,e){void 0!==e&&t.push(e)}function T(t,e,n=!1){var r;if(t===U){for(const t of e)t.output.push(t.defaultUrl);return}n&&(t=S((()=>_(t))));const o=L(t,"`endpoints` value");if(!o)return;const i=A(o.pathname);for(const t of e){const e=null!==(r=t.path)&&void 0!==r?r:"";o.pathname=`${i}${e}`,t.output.push(o.href)}}function L(t,e){const{location:n,URL:r}=window;try{return new r(t,n.href)}catch(n){if(b(n))return console.warn(`Ignoring an invalid ${e} ${JSON.stringify(t)}`),null;throw n}}function P(t,e,n){const r=S((()=>_(t)));e.push(n(A(r)))}function R(t,e){return t===U?e:t}function S(t){try{return t()}catch(t){if(b(t))throw new c(i[e],e);throw t}}function j(t,e){return new Promise((n=>function(t,e,...n){const r=Date.now()+e;let o=0;const i=()=>{o=setTimeout((()=>{Date.now()<r?i():t(...n)}),r-Date.now())};return i(),()=>clearTimeout(o)}(n,t,e)))}function M(t,e){return new Promise(((n,r)=>{let o=!1;null==e||e.then((()=>o=!0),(()=>o=!0));("function"==typeof t?M(Promise.resolve(),e).then(t):t).then((t=>{o||n(t)}),(t=>{o||r(t)}))}))}function O(t,e,n,r){const o=document,i="securitypolicyviolation";let c;const a=e=>{const n=new URL(t,location.href),{blockedURI:r}=e;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(c=e,s())};o.addEventListener(i,a);const s=()=>o.removeEventListener(i,a);return null==r||r.then(s,s),Promise.resolve().then(e).then((t=>(s(),t)),(t=>new Promise((t=>{const e=new MessageChannel;e.port1.onmessage=()=>t(),e.port2.postMessage(null)})).then((()=>{if(s(),c)return n(c);throw t}))))}var I="4.0.0";function W(t,e){F(t,t.len+1),t.arr[t.len++]=e}function B(t,e){F(t,t.len+e.length),t.arr.set(e,t.len),t.len+=e.length}function F(t,e){if(t.arr.length<e){const n=new Uint8Array(Math.max(2*t.arr.length,e));n.set(t.arr),t.arr=n}}function N(t){const e={len:0,arr:new Uint8Array(128)},n=l(t);let r=0;const o=()=>(u(),n[r]===z?i():K(n[r])?c():f(ut)?(r+=ut.length,null):f(ft)?(r+=ft.length,!0):f(lt)?(r+=lt.length,!1):n[r]===it?a():n[r]===at?s():d()),i=()=>{for(e.len=0;r++,n[r]!==z;){if(n[r]===X){if(r++,n[r]===tt){const t=parseInt(h(n.subarray(r+1,r+5)),16);B(e,p(String.fromCharCode(t))),r+=4;continue}const t=pt[n[r]];if(t){W(e,t);continue}return d()}if(void 0===n[r])return d();W(e,n[r])}return r++,h(function(t){return t.arr.subarray(0,t.len)}(e))},c=()=>{const t=r;for(;n[r]===ot||n[r]===Z||n[r]===et||n[r]===nt||K(n[r]);)r++;return Number(h(n.subarray(t,r)))},a=()=>{const t=[];for(r++;;){if(u(),n[r]===ct){r++;break}if(t.length){if(n[r]!==J)return d();r++}t.push(o())}return t},s=()=>{const t={};let e=!0;for(r++;;){if(u(),n[r]===st){r++;break}if(!e){if(n[r]!==J)return d();r++,u()}if(n[r]!==z)return d();const c=i();if(u(),n[r]!==q)return d();r++,Object.defineProperty(t,c,{value:o(),configurable:!0,enumerable:!0,writable:!0}),e=!1}return t},u=()=>{for(;n[r]===H||n[r]===V||n[r]===Q||n[r]===G;)r++},f=t=>{for(let e=0;e<t.length;e++)if(n[r+e]!==t[e])return!1;return!0},d=()=>{throw new SyntaxError("Unexpected "+(r<n.length?`byte ${r}`:"end"))},w=o();return u(),void 0!==n[r]&&d(),w}function K(t){return t>=Y&&t<Y+10||t===rt}const z=34,J=44,q=58,H=32,G=9,Q=13,V=10,X=92,Y=48,Z=101,tt=117,et=69,nt=43,rt=45,ot=46,it=91,ct=93,at=123,st=125,ut=new Uint8Array([110,tt,108,108]),ft=new Uint8Array([116,114,tt,Z]),lt=new Uint8Array([102,97,108,115,Z]),dt={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},pt=(()=>{const t=new Uint8Array(128);for(const[e,n]of Object.entries(dt))t[n.charCodeAt(0)]=e.charCodeAt(0);return t})();var ht=function(t,e){let n;return r=>(n||(n=function(t,e){return N(function(t,e,n){const r=()=>{throw new Error("Invalid data")},o=l(t);o.length<e.length+2&&r();for(let t=0;t<e.length;++t)w(o[1+t],o[0])!==e[t]&&r();const i=1+e.length,c=w(o[i],o[0]);o.length<i+1+c+n&&r();const a=i+1+c,s=a+n,u=new ArrayBuffer(o.length-s),f=new Uint8Array(u);for(let t=0;t<f.length;++t)f[t]=o[s+t]^o[a+t%n];return u}(new Uint32Array(t),[],e))}(t,e)),y(n[r]))}([3501680230,3964354670,1059981298,553689810,78837799,4072876069,3341640258,674045630,775995091,1123205934,2764252002,3932762910],5);const wt=ht(0);function yt(t,e,n,r,o={}){const{maxAttemptCount:i=5,backoffBase:c=200,backoffCap:a=1e4,abort:s}=o,u={failedAttempts:[]},[f,l]=function(t,e,n,r){const o=function(t){const e=[...t];return{current:()=>e[0],postpone(){const t=e.shift();void 0!==t&&e.push(t)},exclude(){e.shift()}}}(t),i=function(t,e){let n=0;return()=>Math.random()*Math.min(e,t*Math.pow(2,n++))}(n,r),c=new Set;return[o.current(),(t,n,r)=>{const a=e(t,n,r);"exclude"===a.action?o.exclude():o.postpone();const s=()=>Math.max(0,t.getTime()+i()-Date.now());let u;u="number"==typeof a.delay?a.delay:s();const f=o.current();if(0===u&&f){Date.now()-t.getTime()<50&&(c.has(f)?u=s():c.add(f))}return void 0===f?void 0:[f,u]}]}(t,r,c,a),d=(p=[null==s?void 0:s.then((t=>u.aborted={resolve:!0,value:t}),(t=>u.aborted={resolve:!1,error:t})),mt(f,i,e,n,l,u,s)],Promise.race(p.filter((t=>!!t)))).then((()=>u));var p;return{then:d.then.bind(d),current:u}}async function mt(t,e,n,r,o,i,c){if(void 0===t)return;let a=t;for(let t=0;t<e;++t){const e=new Date;let s,u;try{s=await M((()=>n(a,t,c)),c)}catch(t){u=t,i.failedAttempts.push({level:0,endpoint:a,error:t})}if(s){const t=r(s);if("result"in t){i.result=t.result;break}if(i.failedAttempts.push({level:1,endpoint:a,error:t.error}),t.stop)break}const f=o(e,s,u);if(!f)break;await M(j(f[1]),c),a=f[0]}}function gt(r,i,a){const s=a instanceof c?a.code:null;if(s===t||s===e)return{action:"exclude",delay:0};if(s===o)return{action:"exclude",delay:"backoff"};if(s===n){return{action:"postpone",delay:Date.now()-r.getTime()<50?0:"backoff"}}return{action:"postpone",delay:"backoff"}}function vt(t){let e,a;const{picked:s,rest:u}=function(t,e){const n={},r={};for(const[o,i]of Object.entries(t))e.includes(o)?n[o]=i:r[o]=i;return{picked:n,rest:r}}(t,["apiKey","region"]),{apiKey:l,region:p}=s,h=d(t,"endpoints");if(!function(t,e){return!(void 0!==t&&"string"!=typeof t&&!f(t))||(Array.isArray(t)?t.every((t=>"string"==typeof t)):!(!$(t)||!t.type||t.type!==e))}(h,wt))throw new c(i[r],r);const[w,y]=function(){const t=[],e=()=>{t.push({time:new Date,state:document.visibilityState})},n=function(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}(document,"visibilitychange",e);return e(),[t,n]}();const m=async function(){try{if(!l||"string"!=typeof l)throw new Error("API key not provided");const t=function(t,e,n){const{script:r}=function(t,e,n=ht(1)){return r=x,o=t,i={region:e,host:n,protocol:ht(2)},r(o,i,!0);var r,o,i}(t,n||"us"),o=null==r?void 0:r.map((t=>function(t,e){const n=new URL(t,window.location.href),r=n.pathname,o="4";return n.pathname=`${r}${r.endsWith("/")?"":"/"}v${o}/${encodeURIComponent(e)}`,n.search=`?ci=jsl/${encodeURIComponent(I)}`,n.href}(t,e)));return o||[]}(h,l,p),[n,r]=await function(t,e){if(0===t.length)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const n=[],r=yt(t,(async t=>{const r=new Date;try{const o=await e(t);return n.push({url:t,startedAt:r,finishedAt:new Date,error:void 0}),o}catch(e){throw n.push({url:t,startedAt:r,finishedAt:new Date,error:e}),e}}),(t=>({result:t})),gt,{maxAttemptCount:5,backoffBase:100,backoffCap:3e3});return new Promise(((t,e)=>{Promise.resolve(r).then((r=>{if(void 0!==r.result)t([r.result,n]);else{const t=r.failedAttempts[0];e(t?t.error:new Error("No attempts were made"))}})).catch(e)}))}(t,bt),o=await n.start({...u,ldi:{attempts:r,visibilityStates:w}});return e=o,o}catch(t){throw a=function(t){if(t instanceof c&&t.code===o)return new c(i[n],n);return t}(t),a}finally{y()}}();return{async get(t){if(e)return e.get(t);if(a)throw a;return(await m).get(t)},async collect(t){if(e)return e.collect(t);if(a)throw a;return(await m).collect(t)}}}function bt(r){return O(r,(async()=>{if(v(r))throw new c(i[e],e);try{return await import(/* webpackIgnore: true */r)}catch(t){throw new c(i[n],n)}}),(()=>{throw new c(i[t],t)})).then((t=>{if("function"!=typeof(null==t?void 0:t.start))throw new c(i[o],o);return t}))}var _t={start:vt,isFingerprintError:a,withoutDefault:u};exports.default=_t,exports.isFingerprintError=a,exports.start=vt,exports.withoutDefault=u;
|
|
5
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t="csp_block",e="invalid_endpoint",n="handle_agent_data",r="script_load_fail",o="api_key_missing",i="api_key_invalid",c="endpoints_misconfigured",a="bundle_not_defined",s={client_timeout:"Client timeout",network_connection:"Network connection error",network_abort:"Network request aborted",[t]:"Blocked by CSP",[e]:'The provided endpoint in "endpoints" parameter is not a valid URL',[n]:"Handle on demand agent data error",[r]:"Failed to load the JS script of the agent",[a]:"9319",bad_response_format:"Can't parse the backend response. Make sure the proper endpoints are used.",[o]:"The `apiKey` option is not provided",[i]:"The `apiKey` option is not a string",cache_misconfigured:"The `cache` option is misconfigured",[c]:"The `endpoints` option is misconfigured",wrong_worker_option:"Wrong `worker` option, it should be a Worker instance",worker_initialization_failed:"Web Worker initialization failed",sandboxed_iframe:"Running inside sandboxed iframes is not supported"};class u extends Error{constructor(t,e){super(t),this.name="FingerprintError",this.event_id=null,this.code=e}}function l(n){return function(t,e,n,r){const o=document,i="securitypolicyviolation";let c;const a=e=>{const n=new URL(t,location.href),{blockedURI:r}=e;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(c=e,s())};o.addEventListener(i,a);const s=()=>o.removeEventListener(i,a);return null==r||r.then(s,s),Promise.resolve().then(e).then((t=>(s(),t)),(t=>new Promise((t=>{const e=new MessageChannel;e.port1.onmessage=()=>t(),e.port2.postMessage(null)})).then((()=>{if(s(),c)return n(c);throw t}))))}(n,(async()=>{if(function(t){if(!URL.prototype)return;try{return new URL(t,location.href),!1}catch(t){if(M(t))return!0;throw t}}(n))throw new u(s[e],e);try{return await import(/* webpackIgnore: true */n)}catch(t){throw new u(s[r],r)}}),(()=>{throw new u(s[t],t)})).then((t=>{if("function"!=typeof(null==t?void 0:t.start))throw new u(s[a],a);return t}))}async function f(t,e,n,r,o,i,c){if(void 0===t)return;let a=t;for(let t=0;t<e;++t){const e=new Date;let s,u;try{s=await g((()=>n(a,t,c)),c)}catch(t){u=t,i.failedAttempts.push({level:0,endpoint:a,error:t})}if(s){const t=r(s);if("result"in t){i.result=t.result;break}if(i.failedAttempts.push({level:1,endpoint:a,error:t.error}),t.stop)break}const l=o(e,s,u);if(!l)break;await g(D(l[1]),c),a=l[0]}}function d(t){let e,n;const{picked:d,rest:h}=function(t,e){const n={},r={};for(const[o,i]of Object.entries(t))e.includes(o)?n[o]=i:r[o]=i;return{picked:n,rest:r}}(t,["apiKey"]),{apiKey:w}=d;if(!w)throw new u(s[o],o);if("string"!=typeof w)throw new u(s[i],i);var m,g;const v=function(t,e){const n=function(t,e){if(void 0===t)return[e];if(y(t))return function(t,e){let n,r=!1;ht(t)?(r=!0,n=vt(t.value)):n=vt(t);const o=[];for(const t of n){const e=st(t,"endpoints");e&&o.push(I(e))}r||o.push(e);return o}(t,e);if(function(t){if(!t||"object"!=typeof t)return!1;const e=t;if("string"!=typeof e.__type__||694409711!==(n=e.__type__,function(t){const e=ft(t);p=p||function(){let t;const e=new Uint32Array(256);for(let n=0;n<256;n++){t=n;for(let e=0;e<8;e++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}();let n=-1;for(let t=0;t<e.length;t++)n=n>>>8^p[255&(n^e[t])];return(-1^n)>>>0}(T(n))))return!1;var n;return(void 0===e.script||y(e.script))&&(void 0===e.helper||y(e.helper))&&(void 0===e.ingress||y(e.ingress))}(t))return function(t,e,n){if(void 0===t)return[e];let r,o=!1;ht(t)?(o=!0,r=vt(t.value)):r=vt(t);const i=[];for(const t of r){const e=st(t,n);e&&i.push(e.href)}o||i.push(e);return i}(t.script,e,"script");return null}(t,"https://fpnpmcdn.net/");if(null===n)throw new u(s[c],c);return n.map((t=>function(t,e){const n=new URL(t,window.location.href),r=n.pathname,o="4";return n.pathname=`${r}${r.endsWith("/")?"":"/"}v${o}/${encodeURIComponent(e)}`,n.search=`?ci=jsl/${encodeURIComponent(U)}`,n.href}(t,e)))}(function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(m=t,g="endpoints")?m[g]:void 0,w),[b,_]=function(){const t=[],e=()=>{t.push({time:new Date,state:document.visibilityState})},n=function(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}(document,"visibilitychange",e);return e(),[t,n]}();const k=async function(){try{const[t,n]=await function(t,e){if(0===t.length)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const n=[],r=function(t,e,n,r,o={}){const{maxAttemptCount:i=5,backoffBase:c=200,backoffCap:a=1e4,abort:s}=o,u={failedAttempts:[]},[l,d]=function(t,e,n,r){const o=function(t){const e=[...t];return{current:()=>e[0],postpone(){const t=e.shift();void 0!==t&&e.push(t)},exclude(){e.shift()}}}(t),i=function(t,e){let n=0;return()=>Math.random()*Math.min(e,t*Math.pow(2,n++))}(n,r),c=new Set;return[o.current(),(t,n,r)=>{const a=e(t,n,r);"exclude"===a.action?o.exclude():o.postpone();const s=()=>Math.max(0,t.getTime()+i()-Date.now());let u;u="number"==typeof a.delay?a.delay:s();const l=o.current();if(0===u&&l){Date.now()-t.getTime()<50&&(c.has(l)?u=s():c.add(l))}return void 0===l?void 0:[l,u]}]}(t,r,c,a),h=(p=[null==s?void 0:s.then((t=>u.aborted={resolve:!0,value:t}),(t=>u.aborted={resolve:!1,error:t})),f(l,i,e,n,d,u,s)],Promise.race(p.filter((t=>!!t)))).then((()=>u));var p;return{then:h.then.bind(h),current:u}}(t,(async t=>{const r=new Date;try{const o=await e(t);return n.push({url:t,startedAt:r,finishedAt:new Date,error:void 0}),o}catch(e){throw n.push({url:t,startedAt:r,finishedAt:new Date,error:e}),e}}),(t=>({result:t})),x,{maxAttemptCount:5,backoffBase:100,backoffCap:3e3});return new Promise(((t,e)=>{Promise.resolve(r).then((r=>{if(void 0!==r.result)t([r.result,n]);else{const t=r.failedAttempts[0];e(t?t.error:new Error("No attempts were made"))}})).catch(e)}))}(v,l),r=await t.start({...h,ldi:{attempts:n,visibilityStates:b}});return e=r,r}catch(t){throw n=function(t){if(t instanceof u&&t.code===a)return new u(s[r],r);return t}(t),n}finally{_()}}();return{async get(t){if(e)return e.get(t);if(n)throw n;return(await k).get(t)},async collect(t){if(e)return e.collect(t);if(n)throw n;return(await k).collect(t)}}}function h(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}let p;const w=Array.isArray;function m(t,e){return(t-e+256)%256}function y(t){return ht(t)?dt(t.value):dt(t)}function g(t,e){return new Promise(((n,r)=>{let o=!1;null==e||e.then((()=>o=!0),(()=>o=!0));("function"==typeof t?g(Promise.resolve(),e).then(t):t).then((t=>{o||n(t)}),(t=>{o||r(t)}))}))}const v="withoutDefault",b="_vid_";function _(t,e){try{document.cookie}catch(t){if(function(t){if(!(t instanceof DOMException))return!1;const e=t.message;return $.test(e)||P.test(e)||L.test(e)}(t))return e;throw t}return t()}function k(t,e){if(t.arr.length<e){const n=new Uint8Array(Math.max(2*t.arr.length,e));n.set(t.arr),t.arr=n}}function A({level:t,message:e}){"error"===t?console.error(e):"warning"===t?console.warn(e):console.log(e)}function x(n,o,i){const c=i instanceof u?i.code:null;if(c===t||c===e)return{action:"exclude",delay:0};if(c===a)return{action:"exclude",delay:"backoff"};if(c===r){return{action:"postpone",delay:Date.now()-n.getTime()<50?0:"backoff"}}return{action:"postpone",delay:"backoff"}}var U="4.0.1";function C(t){return t>=q&&t<q+10||t===Q}function D(t,e){return new Promise((n=>function(t,e,...n){const r=Date.now()+e;let o=0;const i=()=>{o=setTimeout((()=>{Date.now()<r?i():t(...n)}),r-Date.now())};return i(),()=>clearTimeout(o)}(n,t,e)))}function E(t){if("function"==typeof TextDecoder){const e=(new TextDecoder).decode(t);if(e)return e}const e=ft(t);return decodeURIComponent(escape(String.fromCharCode.apply(null,e)))}function T(t){const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>127)return(new TextEncoder).encode(t);e[n]=r}return e}function S(t,e,...n){t&&async function(t,e){try{await t()}catch(t){return console.error(t),e}}((()=>{const r=e(...n);void 0!==r&&t(r)}))}const $=/The document is sandboxed and lacks the 'allow-same-origin' flag/,P=/The operation is insecure/,L=/Forbidden in a sandboxed document without the 'allow-same-origin' flag/;function M(t){return t instanceof Error&&"TypeError"===t.name}function R(){return function(){var t,e;const n=window;return["buildID"in navigator,"MozAppearance"in(null!==(e=null===(t=document.documentElement)||void 0===t?void 0:t.style)&&void 0!==e?e:{}),"onmozfullscreenchange"in n,"mozInnerScreenX"in n,"CSSMozDocumentRule"in n,"CanvasCaptureMediaStream"in n].reduce(((t,e)=>t+(e?1:0)),0)>=4}()}function I(t){return`${t.origin}${t.pathname.endsWith("/")?t.pathname:`${t.pathname}/`}web/`}const j=34,O=44,F=58,z=32,W=9,B=13,K=10,N=92,q=48,H=101,J=117,X=69,G=43,Q=45,V=46,Y=91,Z=93,tt=123,et=125,nt=new Uint8Array([110,J,108,108]),rt=new Uint8Array([116,114,J,H]),ot=new Uint8Array([102,97,108,115,H]),it={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},ct=(()=>{const t=new Uint8Array(128);for(const[e,n]of Object.entries(it))t[n.charCodeAt(0)]=e.charCodeAt(0);return t})();function at(t,e){k(t,t.len+1),t.arr[t.len++]=e}function st(t,e){try{return new window.URL(t,window.location.href)}catch(n){if(M(n))return console.warn(`Ignoring an invalid '${e}' value: "${t}"`),null;throw n}}function ut(t){return{__type__:v,value:t}}function lt(t,e,n,r){_((()=>{const o=`${t}=${e}`,i=`expires=${new Date(Date.now()+24*n*60*60*1e3).toUTCString()}`,c=r?`domain=${r}`:"";document.cookie=[o,"path=/",i,c,"SameSite=Lax"].join("; ")}),void 0)}function ft(t){return t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function dt(t){return"string"==typeof t||Array.isArray(t)&&t.every((t=>"string"==typeof t))}function ht(t){return!!t&&t.__type__===v}function pt(t,e){k(t,t.len+e.length),t.arr.set(e,t.len),t.len+=e.length}function wt(t){const e=location.hostname,n=R();(function(t,e){let n=t.length-("."===t.slice(-1)?1:0);do{if(n=n>0?t.lastIndexOf(".",n-1):-1,!0===e(t.slice(n+1)))return!0}while(n>=0);return!1})(e,(r=>{if(!n||!/^([^.]{1,3}\.)*[^.]+\.?$/.test(r)||r===e)return t(r)}))||t()}const mt=[3,13],yt=[3,14],gt=9;function vt(t){return w(t)?t:[t]}const bt=function(t,e={}){const{storageKeyPrefix:r=b,do:o}=e;try{const e=function(t){const e=function(t){const e=atob(t),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r}(t);let n=e;try{n=function(t,e,n){const r=()=>{throw new Error("Invalid data")},o=ft(t);o.length<e.length+2&&r();for(let t=0;t<e.length;++t)m(o[1+t],o[0])!==e[t]&&r();const i=1+e.length,c=m(o[i],o[0]);o.length<i+1+c+n&&r();const a=i+1+c,s=a+n,u=new ArrayBuffer(o.length-s),l=new Uint8Array(u);for(let t=0;t<l.length;++t)l[t]=o[s+t]^o[a+t%n];return u}(e,!1?yt:mt,gt)}catch(t){}try{return function(t){const e={len:0,arr:new Uint8Array(128)},n=ft(t);let r=0;const o=()=>(u(),n[r]===j?i():C(n[r])?c():l(nt)?(r+=nt.length,null):l(rt)?(r+=rt.length,!0):l(ot)?(r+=ot.length,!1):n[r]===Y?a():n[r]===tt?s():f()),i=()=>{for(e.len=0;r++,n[r]!==j;){if(n[r]===N){if(r++,n[r]===J){const t=parseInt(E(n.subarray(r+1,r+5)),16);pt(e,T(String.fromCharCode(t))),r+=4;continue}const t=ct[n[r]];if(t){at(e,t);continue}return f()}if(void 0===n[r])return f();at(e,n[r])}return r++,E(function(t){return t.arr.subarray(0,t.len)}(e))},c=()=>{const t=r;for(;n[r]===V||n[r]===H||n[r]===X||n[r]===G||C(n[r]);)r++;return Number(E(n.subarray(t,r)))},a=()=>{const t=[];for(r++;;){if(u(),n[r]===Z){r++;break}if(t.length){if(n[r]!==O)return f();r++}t.push(o())}return t},s=()=>{const t={};let e=!0;for(r++;;){if(u(),n[r]===et){r++;break}if(!e){if(n[r]!==O)return f();r++,u()}if(n[r]!==j)return f();const c=i();if(u(),n[r]!==F)return f();r++,Object.defineProperty(t,c,{value:o(),configurable:!0,enumerable:!0,writable:!0}),e=!1}return t},u=()=>{for(;n[r]===z||n[r]===K||n[r]===B||n[r]===W;)r++},l=t=>{for(let e=0;e<t.length;e++)if(n[r+e]!==t[e])return!1;return!0},f=()=>{throw new SyntaxError("Unexpected "+(r<n.length?`byte ${r}`:"end"))},d=o();u(),void 0!==n[r]&&f();return d}(n)}catch(t){}return null}(t);null!==e?(e.visitorToken&&(l=e.visitorToken,i=f=`${r}t`,c=l,a=365,wt((t=>{!function(t,e){lt(t,"",-1,e)}(i,t)})),a<0||wt((t=>(lt(i,c,a,t),function(t){return _((()=>{const e=`${t}=`;for(const t of document.cookie.split(";")){let n=0;for(;" "===t[n]&&n<t.length;)++n;if(t.indexOf(e)===n)return t.slice(n+e.length)}}),void 0)}(i)===c))),function(t,e){var n;try{null===(n=null===localStorage||void 0===localStorage?void 0:localStorage.setItem)||void 0===n||n.call(localStorage,t,e)}catch(t){}}(f,l)),e.notifications.forEach(A),S(o,(()=>({e:25,result:{response:e}})))):S(o,(()=>({e:25,result:{error:new Error("Failed to decode response")}})))}catch(t){throw S(o,(()=>({e:25,result:{error:t instanceof Error?t:new Error(String(t))}}))),new u(s[n],n)}var i,c,a,l,f};var _t={start:d,handleAgentData:bt,isFingerprintError:h,withoutDefault:ut};exports.default=_t,exports.handleAgentData=bt,exports.isFingerprintError=h,exports.start=d,exports.withoutDefault=ut;
|
package/dist/fp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Fingerprint v4.0.
|
|
2
|
+
* Fingerprint v4.0.1 - Copyright (c) FingerprintJS, Inc, 2026 (https://fingerprint.com)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
declare const ERROR_CODE_CLIENT_TIMEOUT: "client_timeout";
|
|
@@ -112,7 +112,7 @@ type Region =
|
|
|
112
112
|
| 'eu'
|
|
113
113
|
/** Mumbai, India */
|
|
114
114
|
| 'ap';
|
|
115
|
-
declare const withoutDefaultType
|
|
115
|
+
declare const withoutDefaultType = "withoutDefault";
|
|
116
116
|
/**
|
|
117
117
|
* This object wraps a parameter to tell JS Agent that you don't want to use the default value.
|
|
118
118
|
* Don't compose it manually, use `withoutDefault` instead.
|
|
@@ -203,6 +203,15 @@ type LoaderStartOptions = {
|
|
|
203
203
|
*/
|
|
204
204
|
cache?: CacheConfig;
|
|
205
205
|
};
|
|
206
|
+
/**
|
|
207
|
+
* Any simple value or an object (not arrays)
|
|
208
|
+
* Constraint: the size must not exceed 16KB.
|
|
209
|
+
*/
|
|
210
|
+
type TagPrimitive = string | number | boolean;
|
|
211
|
+
type TagValueObject = {
|
|
212
|
+
[key: string]: TagValue | TagValue[];
|
|
213
|
+
};
|
|
214
|
+
type TagValue = null | TagPrimitive | TagValueObject;
|
|
206
215
|
/**
|
|
207
216
|
* Options for requesting the visitor information
|
|
208
217
|
*/
|
|
@@ -223,7 +232,7 @@ type PublicGetOptions = {
|
|
|
223
232
|
* Anything that identifies a visitor or a request.
|
|
224
233
|
* You can pass the event_id as a `tag` and then get this event_id back in the webhook, associated with a visitorId.
|
|
225
234
|
*/
|
|
226
|
-
tag?:
|
|
235
|
+
tag?: TagValue;
|
|
227
236
|
/**
|
|
228
237
|
* `linkedId` is a way of linking current identification event with a custom identifier.
|
|
229
238
|
* This can be helpful to be able to filter API visit information later.
|
|
@@ -234,6 +243,17 @@ type PublicGetOptions = {
|
|
|
234
243
|
* Options of collecting on demand fingerprint data
|
|
235
244
|
*/
|
|
236
245
|
type PublicCollectOptions = PublicGetOptions;
|
|
246
|
+
/**
|
|
247
|
+
* Options of handling on demand agent data
|
|
248
|
+
*/
|
|
249
|
+
type PublicHandleAgentDataOptions = {
|
|
250
|
+
/**
|
|
251
|
+
* Override storages name (cookies, localStorage, etc).
|
|
252
|
+
* Should only be used when the default name conflicts with some of your existing names.
|
|
253
|
+
* @default '_vid'
|
|
254
|
+
*/
|
|
255
|
+
storageKeyPrefix?: string;
|
|
256
|
+
};
|
|
237
257
|
/**
|
|
238
258
|
* Wraps a parameter to tell JS Agent that you don't want to use the default value
|
|
239
259
|
*/
|
|
@@ -254,14 +274,22 @@ interface PublicAgent {
|
|
|
254
274
|
*/
|
|
255
275
|
collect(options?: Readonly<PublicCollectOptions>): Promise<CollectResult>;
|
|
256
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Handles the on demand agent data sent from the remote agent.
|
|
279
|
+
* Intended for use in integrations where response data is received out-of-band (via /send endpoint).
|
|
280
|
+
*
|
|
281
|
+
* @throws FingerprintError with code 'handle_agent_data' if `response` is malformed.
|
|
282
|
+
*/
|
|
283
|
+
declare const publicHandleAgentData: (data: string, options?: Readonly<PublicHandleAgentDataOptions> | undefined) => void;
|
|
257
284
|
|
|
258
285
|
type StartOptions = LoaderStartOptions;
|
|
259
286
|
declare function start(options: StartOptions): PublicAgent;
|
|
260
287
|
|
|
261
288
|
declare const _default: {
|
|
262
289
|
start: typeof start;
|
|
290
|
+
handleAgentData: (data: string, options?: Readonly<PublicHandleAgentDataOptions> | undefined) => void;
|
|
263
291
|
isFingerprintError: typeof isFingerprintError;
|
|
264
292
|
withoutDefault: typeof withoutDefault;
|
|
265
293
|
};
|
|
266
294
|
|
|
267
|
-
export { type PublicAgent as Agent, type FingerprintErrorInterface as Error, type FingerprintErrorCode as ErrorCode, type PublicGetOptions as GetOptions, type PublicGetResult as GetResult, type StartOptions, _default as default, isFingerprintError, start, withoutDefault };
|
|
295
|
+
export { type PublicAgent as Agent, type FingerprintErrorInterface as Error, type FingerprintErrorCode as ErrorCode, type PublicGetOptions as GetOptions, type PublicGetResult as GetResult, type StartOptions, _default as default, publicHandleAgentData as handleAgentData, isFingerprintError, start, withoutDefault };
|
package/dist/fp.esm.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Fingerprint v4.0.
|
|
2
|
+
* Fingerprint v4.0.1 - Copyright (c) FingerprintJS, Inc, 2026 (https://fingerprint.com)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const t="csp_block",n="invalid_endpoint",e="script_load_fail",r="endpoints_misconfigured",o="bundle_not_defined",i={client_timeout:"Client timeout",network_connection:"Network connection error",network_abort:"Network request aborted",[t]:"Blocked by CSP",[n]:'The provided endpoint in "endpoints" parameter is not a valid URL',handle_agent_data:"Handle on demand agent data error",[e]:"Failed to load the JS script of the agent",[o]:"9319",bad_response_format:"Can't parse the backend response. Make sure the proper endpoints are used.",api_key_missing:"The `apiKey` option is not provided",api_key_invalid:"The `apiKey` option is not a string",cache_misconfigured:"The `cache` option is misconfigured",[r]:"The `endpoints` option is misconfigured",wrong_worker_option:"Wrong `worker` option, it should be a Worker instance",worker_initialization_failed:"Web Worker initialization failed",sandboxed_iframe:"Running inside sandboxed iframes is not supported"};class c extends Error{constructor(t,n){super(t),this.name="FingerprintError",this.event_id=null,this.code=n}}function a(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}const u=/*#__PURE__*/Symbol("withoutDefault");function s(t){return{__type__:u,value:t}}function f(t){return!!t&&t.__type__===u}function l(t){return t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function d(t,n){return function(t,n){return Object.prototype.hasOwnProperty.call(t,n)}(t,n)?t[n]:void 0}function p(t){const n=new Uint8Array(t.length);for(let e=0;e<t.length;e++){const r=t.charCodeAt(e);if(r>127)return(new TextEncoder).encode(t);n[e]=r}return n}function h(t){if("function"==typeof TextDecoder){const n=(new TextDecoder).decode(t);if(n)return n}const n=l(t);return decodeURIComponent(escape(String.fromCharCode.apply(null,n)))}function w(t,n){return(t-n+256)%256}function y(t){if(t instanceof Array)return t.map(y);if(t&&"object"==typeof t){const n={};for(const e of Object.keys(t))n[e]=y(t[e]);return n}return t}function m(t){return g(t)?t:[t]}const g=Array.isArray;function v(t){if(URL.prototype)try{return new URL(t,location.href),!1}catch(t){if(b(t))return!0;throw t}}function b(t){return t instanceof Error&&"TypeError"===t.name}function A(t){if(v(t))return t;const n=new URL(t);return n.search="",n.toString()}function _(t){return t.endsWith("/")?t:`${t}/`}const k="https://fpnpmcdn.net/",U=/*#__PURE__*/Symbol("default");function $(t,n,e=!1,r){const o=e?function(t){const{protocol:n}=t;return`${n}://${new URL(k).host}/`}(n):function(t){const{region:n,protocol:e}=t;let r=t.host;"us"!==n&&(r=`${n}.${r}`);return`${e}://${r}/`}(n);return e?function(t,n){const e="web",r=[],o=t===k?`${t}`:`${t}${e}`;if(x(n))C(n.script,o,r,"script");else for(const t of E(n))D(t,[{defaultUrl:o,output:r,path:e}],!0);return{script:r}}(o,t):function(t,n,e){const r=[],o=[];if(x(n))C(n.helper,t,r,"helper"),C(n.ingress,t,o,"ingress");else for(const i of E(n))e?R(P(i,t),r,e):D(i,[{defaultUrl:t,output:r}]),D(i,[{defaultUrl:t,output:o}]);return{helper:r,get:o}}(o,t,r)}function x(t){return!!t&&"object"==typeof t&&!Array.isArray(t)&&!f(t)}function C(t,n,e,r){var o;for(const i of E(t)){T(e,i===U?n:null===(o=L(i,`\`${r}\` endpoint`))||void 0===o?void 0:o.href)}}function E(t){return f(t)?m(t.value):void 0===t?[U]:[...m(t),U]}function T(t,n){void 0!==n&&t.push(n)}function D(t,n,e=!1){var r;if(t===U){for(const t of n)t.output.push(t.defaultUrl);return}e&&(t=S((()=>A(t))));const o=L(t,"`endpoints` value");if(!o)return;const i=_(o.pathname);for(const t of n){const n=null!==(r=t.path)&&void 0!==r?r:"";o.pathname=`${i}${n}`,t.output.push(o.href)}}function L(t,n){const{location:e,URL:r}=window;try{return new r(t,e.href)}catch(e){if(b(e))return console.warn(`Ignoring an invalid ${n} ${JSON.stringify(t)}`),null;throw e}}function R(t,n,e){const r=S((()=>A(t)));n.push(e(_(r)))}function P(t,n){return t===U?n:t}function S(t){try{return t()}catch(t){if(b(t))throw new c(i[n],n);throw t}}function j(t,n){return new Promise((e=>function(t,n,...e){const r=Date.now()+n;let o=0;const i=()=>{o=setTimeout((()=>{Date.now()<r?i():t(...e)}),r-Date.now())};return i(),()=>clearTimeout(o)}(e,t,n)))}function I(t,n){return new Promise(((e,r)=>{let o=!1;null==n||n.then((()=>o=!0),(()=>o=!0));("function"==typeof t?I(Promise.resolve(),n).then(t):t).then((t=>{o||e(t)}),(t=>{o||r(t)}))}))}function M(t,n,e,r){const o=document,i="securitypolicyviolation";let c;const a=n=>{const e=new URL(t,location.href),{blockedURI:r}=n;r!==e.href&&r!==e.protocol.slice(0,-1)&&r!==e.origin||(c=n,u())};o.addEventListener(i,a);const u=()=>o.removeEventListener(i,a);return null==r||r.then(u,u),Promise.resolve().then(n).then((t=>(u(),t)),(t=>new Promise((t=>{const n=new MessageChannel;n.port1.onmessage=()=>t(),n.port2.postMessage(null)})).then((()=>{if(u(),c)return e(c);throw t}))))}var O="4.0.0";function W(t,n){N(t,t.len+1),t.arr[t.len++]=n}function B(t,n){N(t,t.len+n.length),t.arr.set(n,t.len),t.len+=n.length}function N(t,n){if(t.arr.length<n){const e=new Uint8Array(Math.max(2*t.arr.length,n));e.set(t.arr),t.arr=e}}function F(t){const n={len:0,arr:new Uint8Array(128)},e=l(t);let r=0;const o=()=>(s(),e[r]===z?i():K(e[r])?c():f(st)?(r+=st.length,null):f(ft)?(r+=ft.length,!0):f(lt)?(r+=lt.length,!1):e[r]===it?a():e[r]===at?u():d()),i=()=>{for(n.len=0;r++,e[r]!==z;){if(e[r]===X){if(r++,e[r]===tt){const t=parseInt(h(e.subarray(r+1,r+5)),16);B(n,p(String.fromCharCode(t))),r+=4;continue}const t=pt[e[r]];if(t){W(n,t);continue}return d()}if(void 0===e[r])return d();W(n,e[r])}return r++,h(function(t){return t.arr.subarray(0,t.len)}(n))},c=()=>{const t=r;for(;e[r]===ot||e[r]===Z||e[r]===nt||e[r]===et||K(e[r]);)r++;return Number(h(e.subarray(t,r)))},a=()=>{const t=[];for(r++;;){if(s(),e[r]===ct){r++;break}if(t.length){if(e[r]!==J)return d();r++}t.push(o())}return t},u=()=>{const t={};let n=!0;for(r++;;){if(s(),e[r]===ut){r++;break}if(!n){if(e[r]!==J)return d();r++,s()}if(e[r]!==z)return d();const c=i();if(s(),e[r]!==q)return d();r++,Object.defineProperty(t,c,{value:o(),configurable:!0,enumerable:!0,writable:!0}),n=!1}return t},s=()=>{for(;e[r]===H||e[r]===V||e[r]===Q||e[r]===G;)r++},f=t=>{for(let n=0;n<t.length;n++)if(e[r+n]!==t[n])return!1;return!0},d=()=>{throw new SyntaxError("Unexpected "+(r<e.length?`byte ${r}`:"end"))},w=o();return s(),void 0!==e[r]&&d(),w}function K(t){return t>=Y&&t<Y+10||t===rt}const z=34,J=44,q=58,H=32,G=9,Q=13,V=10,X=92,Y=48,Z=101,tt=117,nt=69,et=43,rt=45,ot=46,it=91,ct=93,at=123,ut=125,st=/*#__PURE__*/new Uint8Array([110,tt,108,108]),ft=/*#__PURE__*/new Uint8Array([116,114,tt,Z]),lt=/*#__PURE__*/new Uint8Array([102,97,108,115,Z]),dt={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},pt=/*#__PURE__*/(()=>{const t=new Uint8Array(128);for(const[n,e]of Object.entries(dt))t[e.charCodeAt(0)]=n.charCodeAt(0);return t})();var ht=function(t,n){let e;return r=>(e||(e=function(t,n){return F(function(t,n,e){const r=()=>{throw new Error("Invalid data")},o=l(t);o.length<n.length+2&&r();for(let t=0;t<n.length;++t)w(o[1+t],o[0])!==n[t]&&r();const i=1+n.length,c=w(o[i],o[0]);o.length<i+1+c+e&&r();const a=i+1+c,u=a+e,s=new ArrayBuffer(o.length-u),f=new Uint8Array(s);for(let t=0;t<f.length;++t)f[t]=o[u+t]^o[a+t%e];return s}(new Uint32Array(t),[],n))}(t,n)),y(e[r]))}([3501680230,3964354670,1059981298,553689810,78837799,4072876069,3341640258,674045630,775995091,1123205934,2764252002,3932762910],5);const wt=ht(0);function yt(t,n,e,r,o={}){const{maxAttemptCount:i=5,backoffBase:c=200,backoffCap:a=1e4,abort:u}=o,s={failedAttempts:[]},[f,l]=function(t,n,e,r){const o=function(t){const n=[...t];return{current:()=>n[0],postpone(){const t=n.shift();void 0!==t&&n.push(t)},exclude(){n.shift()}}}(t),i=function(t,n){let e=0;return()=>Math.random()*Math.min(n,t*Math.pow(2,e++))}(e,r),c=new Set;return[o.current(),(t,e,r)=>{const a=n(t,e,r);"exclude"===a.action?o.exclude():o.postpone();const u=()=>Math.max(0,t.getTime()+i()-Date.now());let s;s="number"==typeof a.delay?a.delay:u();const f=o.current();if(0===s&&f){Date.now()-t.getTime()<50&&(c.has(f)?s=u():c.add(f))}return void 0===f?void 0:[f,s]}]}(t,r,c,a),d=(p=[null==u?void 0:u.then((t=>s.aborted={resolve:!0,value:t}),(t=>s.aborted={resolve:!1,error:t})),mt(f,i,n,e,l,s,u)],Promise.race(p.filter((t=>!!t)))).then((()=>s));var p;return{then:d.then.bind(d),current:s}}async function mt(t,n,e,r,o,i,c){if(void 0===t)return;let a=t;for(let t=0;t<n;++t){const n=new Date;let u,s;try{u=await I((()=>e(a,t,c)),c)}catch(t){s=t,i.failedAttempts.push({level:0,endpoint:a,error:t})}if(u){const t=r(u);if("result"in t){i.result=t.result;break}if(i.failedAttempts.push({level:1,endpoint:a,error:t.error}),t.stop)break}const f=o(n,u,s);if(!f)break;await I(j(f[1]),c),a=f[0]}}function gt(r,i,a){const u=a instanceof c?a.code:null;if(u===t||u===n)return{action:"exclude",delay:0};if(u===o)return{action:"exclude",delay:"backoff"};if(u===e){return{action:"postpone",delay:Date.now()-r.getTime()<50?0:"backoff"}}return{action:"postpone",delay:"backoff"}}function vt(t){let n,a;const{picked:u,rest:s}=function(t,n){const e={},r={};for(const[o,i]of Object.entries(t))n.includes(o)?e[o]=i:r[o]=i;return{picked:e,rest:r}}(t,["apiKey","region"]),{apiKey:l,region:p}=u,h=d(t,"endpoints");if(!function(t,n){return!(void 0!==t&&"string"!=typeof t&&!f(t))||(Array.isArray(t)?t.every((t=>"string"==typeof t)):!(!x(t)||!t.type||t.type!==n))}(h,wt))throw new c(i[r],r);const[w,y]=function(){const t=[],n=()=>{t.push({time:new Date,state:document.visibilityState})},e=function(t,n,e,r){return t.addEventListener(n,e,r),()=>t.removeEventListener(n,e,r)}(document,"visibilitychange",n);return n(),[t,e]}();const m=async function(){try{if(!l||"string"!=typeof l)throw new Error("API key not provided");const t=function(t,n,e){const{script:r}=function(t,n,e=ht(1)){return r=$,o=t,i={region:n,host:e,protocol:ht(2)},r(o,i,!0);var r,o,i}(t,e||"us"),o=null==r?void 0:r.map((t=>function(t,n){const e=new URL(t,window.location.href),r=e.pathname,o="4";return e.pathname=`${r}${r.endsWith("/")?"":"/"}v${o}/${encodeURIComponent(n)}`,e.search=`?ci=jsl/${encodeURIComponent(O)}`,e.href}(t,n)));return o||[]}(h,l,p),[e,r]=await function(t,n){if(0===t.length)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const e=[],r=yt(t,(async t=>{const r=new Date;try{const o=await n(t);return e.push({url:t,startedAt:r,finishedAt:new Date,error:void 0}),o}catch(n){throw e.push({url:t,startedAt:r,finishedAt:new Date,error:n}),n}}),(t=>({result:t})),gt,{maxAttemptCount:5,backoffBase:100,backoffCap:3e3});return new Promise(((t,n)=>{Promise.resolve(r).then((r=>{if(void 0!==r.result)t([r.result,e]);else{const t=r.failedAttempts[0];n(t?t.error:new Error("No attempts were made"))}})).catch(n)}))}(t,bt),o=await e.start({...s,ldi:{attempts:r,visibilityStates:w}});return n=o,o}catch(t){throw a=function(t){if(t instanceof c&&t.code===o)return new c(i[e],e);return t}(t),a}finally{y()}}();return{async get(t){if(n)return n.get(t);if(a)throw a;return(await m).get(t)},async collect(t){if(n)return n.collect(t);if(a)throw a;return(await m).collect(t)}}}function bt(r){return M(r,(async()=>{if(v(r))throw new c(i[n],n);try{return await import(/* webpackIgnore: true */r)}catch(t){throw new c(i[e],e)}}),(()=>{throw new c(i[t],t)})).then((t=>{if("function"!=typeof(null==t?void 0:t.start))throw new c(i[o],o);return t}))}var At={start:vt,isFingerprintError:a,withoutDefault:s};export{At as default,a as isFingerprintError,vt as start,s as withoutDefault};
|
|
5
|
+
const t="csp_block",e="invalid_endpoint",n="handle_agent_data",r="script_load_fail",o="api_key_missing",i="api_key_invalid",a="endpoints_misconfigured",c="bundle_not_defined",s={client_timeout:"Client timeout",network_connection:"Network connection error",network_abort:"Network request aborted",[t]:"Blocked by CSP",[e]:'The provided endpoint in "endpoints" parameter is not a valid URL',[n]:"Handle on demand agent data error",[r]:"Failed to load the JS script of the agent",[c]:"9319",bad_response_format:"Can't parse the backend response. Make sure the proper endpoints are used.",[o]:"The `apiKey` option is not provided",[i]:"The `apiKey` option is not a string",cache_misconfigured:"The `cache` option is misconfigured",[a]:"The `endpoints` option is misconfigured",wrong_worker_option:"Wrong `worker` option, it should be a Worker instance",worker_initialization_failed:"Web Worker initialization failed",sandboxed_iframe:"Running inside sandboxed iframes is not supported"};class u extends Error{constructor(t,e){super(t),this.name="FingerprintError",this.event_id=null,this.code=e}}function l(t,e){if(0===t.length)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const n=[],r=function(t,e,n,r,o={}){const{maxAttemptCount:i=5,backoffBase:a=200,backoffCap:c=1e4,abort:s}=o,u={failedAttempts:[]},[l,f]=function(t,e,n,r){const o=function(t){const e=[...t];return{current:()=>e[0],postpone(){const t=e.shift();void 0!==t&&e.push(t)},exclude(){e.shift()}}}(t),i=function(t,e){let n=0;return()=>Math.random()*Math.min(e,t*Math.pow(2,n++))}(n,r),a=new Set;return[o.current(),(t,n,r)=>{const c=e(t,n,r);"exclude"===c.action?o.exclude():o.postpone();const s=()=>Math.max(0,t.getTime()+i()-Date.now());let u;u="number"==typeof c.delay?c.delay:s();const l=o.current();if(0===u&&l){Date.now()-t.getTime()<50&&(a.has(l)?u=s():a.add(l))}return void 0===l?void 0:[l,u]}]}(t,r,a,c),d=(h=[null==s?void 0:s.then((t=>u.aborted={resolve:!0,value:t}),(t=>u.aborted={resolve:!1,error:t})),nt(l,i,e,n,f,u,s)],Promise.race(h.filter((t=>!!t)))).then((()=>u));var h;return{then:d.then.bind(d),current:u}}(t,(async t=>{const r=new Date;try{const o=await e(t);return n.push({url:t,startedAt:r,finishedAt:new Date,error:void 0}),o}catch(e){throw n.push({url:t,startedAt:r,finishedAt:new Date,error:e}),e}}),(t=>({result:t})),K,{maxAttemptCount:5,backoffBase:100,backoffCap:3e3});return new Promise(((t,e)=>{Promise.resolve(r).then((r=>{if(void 0!==r.result)t([r.result,n]);else{const t=r.failedAttempts[0];e(t?t.error:new Error("No attempts were made"))}})).catch(e)}))}function f(t){return!!t&&t.__type__===A}function d(t){const e=k(t);h=h||function(){let t;const e=new Uint32Array(256);for(let n=0;n<256;n++){t=n;for(let e=0;e<8;e++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}();let n=-1;for(let t=0;t<e.length;t++)n=n>>>8^h[255&(n^e[t])];return(-1^n)>>>0}let h;function p(t){return f(t)?tt(t.value):tt(t)}function w(t,e,...n){t&&async function(t,e){try{await t()}catch(t){return console.error(t),e}}((()=>{const r=e(...n);void 0!==r&&t(r)}))}function m(t,e){if(t.arr.length<e){const n=new Uint8Array(Math.max(2*t.arr.length,e));n.set(t.arr),t.arr=n}}const y=Array.isArray;function g(t){const e=location.hostname,n=function(){var t,e;const n=window;return["buildID"in navigator,"MozAppearance"in(null!==(e=null===(t=document.documentElement)||void 0===t?void 0:t.style)&&void 0!==e?e:{}),"onmozfullscreenchange"in n,"mozInnerScreenX"in n,"CSSMozDocumentRule"in n,"CanvasCaptureMediaStream"in n].reduce(((t,e)=>t+(e?1:0)),0)>=4}();(function(t,e){let n=t.length-("."===t.slice(-1)?1:0);do{if(n=n>0?t.lastIndexOf(".",n-1):-1,!0===e(t.slice(n+1)))return!0}while(n>=0);return!1})(e,(r=>{if(!n||!/^([^.]{1,3}\.)*[^.]+\.?$/.test(r)||r===e)return t(r)}))||t()}function v(t,e){return function(t,e,n){const r=()=>{throw new Error("Invalid data")},o=k(t);o.length<e.length+2&&r();for(let t=0;t<e.length;++t)$(o[1+t],o[0])!==e[t]&&r();const i=1+e.length,a=$(o[i],o[0]);o.length<i+1+a+n&&r();const c=i+1+a,s=c+n,u=new ArrayBuffer(o.length-s),l=new Uint8Array(u);for(let t=0;t<l.length;++t)l[t]=o[s+t]^o[c+t%n];return u}(t,e?ct:at,st)}function b(t,e,n){g((e=>{!function(t,e){P(t,"",-1,e)}(t,e)})),n<0||g((r=>(P(t,e,n,r),function(t){return D((()=>{const e=`${t}=`;for(const t of document.cookie.split(";")){let n=0;for(;" "===t[n]&&n<t.length;)++n;if(t.indexOf(e)===n)return t.slice(n+e.length)}}),void 0)}(t)===e)))}function _(t,e,n,r){const o=document,i="securitypolicyviolation";let a;const c=e=>{const n=new URL(t,location.href),{blockedURI:r}=e;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(a=e,s())};o.addEventListener(i,c);const s=()=>o.removeEventListener(i,c);return null==r||r.then(s,s),Promise.resolve().then(e).then((t=>(s(),t)),(t=>new Promise((t=>{const e=new MessageChannel;e.port1.onmessage=()=>t(),e.port2.postMessage(null)})).then((()=>{if(s(),a)return n(a);throw t}))))}function k(t){return t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}const A="withoutDefault",x="_vid_";function U(t){return t instanceof Error&&"TypeError"===t.name}function C(t,e){m(t,t.len+e.length),t.arr.set(e,t.len),t.len+=e.length}function D(t,e){try{document.cookie}catch(t){if(function(t){if(!(t instanceof DOMException))return!1;const e=t.message;return I.test(e)||j.test(e)||O.test(e)}(t))return e;throw t}return t()}function E(t,e){try{return new window.URL(t,window.location.href)}catch(n){if(U(n))return console.warn(`Ignoring an invalid '${e}' value: "${t}"`),null;throw n}}function T(t){const e=function(t){const e=atob(t),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r}(t);let n=e;try{n=v(e,!1)}catch(t){}try{return function(t){const e={len:0,arr:new Uint8Array(128)},n=k(t);let r=0;const o=()=>(u(),n[r]===N?i():W(n[r])?a():l(G)?(r+=G.length,null):l(Q)?(r+=Q.length,!0):l(V)?(r+=V.length,!1):91===n[r]?c():123===n[r]?s():f()),i=()=>{for(e.len=0;r++,n[r]!==N;){if(92===n[r]){if(r++,n[r]===J){const t=parseInt(z(n.subarray(r+1,r+5)),16);C(e,ut(String.fromCharCode(t))),r+=4;continue}const t=Z[n[r]];if(t){L(e,t);continue}return f()}if(void 0===n[r])return f();L(e,n[r])}return r++,z(function(t){return t.arr.subarray(0,t.len)}(e))},a=()=>{const t=r;for(;46===n[r]||n[r]===H||69===n[r]||43===n[r]||W(n[r]);)r++;return Number(z(n.subarray(t,r)))},c=()=>{const t=[];for(r++;;){if(u(),93===n[r]){r++;break}if(t.length){if(44!==n[r])return f();r++}t.push(o())}return t},s=()=>{const t={};let e=!0;for(r++;;){if(u(),125===n[r]){r++;break}if(!e){if(44!==n[r])return f();r++,u()}if(n[r]!==N)return f();const a=i();if(u(),58!==n[r])return f();r++,Object.defineProperty(t,a,{value:o(),configurable:!0,enumerable:!0,writable:!0}),e=!1}return t},u=()=>{for(;32===n[r]||10===n[r]||13===n[r]||9===n[r];)r++},l=t=>{for(let e=0;e<t.length;e++)if(n[r+e]!==t[e])return!1;return!0},f=()=>{throw new SyntaxError("Unexpected "+(r<n.length?`byte ${r}`:"end"))},d=o();u(),void 0!==n[r]&&f();return d}(n)}catch(t){}return null}function S(n){return _(n,(async()=>{if(function(t){if(!URL.prototype)return;try{return new URL(t,location.href),!1}catch(t){if(U(t))return!0;throw t}}(n))throw new u(s[e],e);try{return await import(/* webpackIgnore: true */n)}catch(t){throw new u(s[r],r)}}),(()=>{throw new u(s[t],t)})).then((t=>{if("function"!=typeof(null==t?void 0:t.start))throw new u(s[c],c);return t}))}function $(t,e){return(t-e+256)%256}function L(t,e){m(t,t.len+1),t.arr[t.len++]=e}function P(t,e,n,r){D((()=>{const o=`${t}=${e}`,i=`expires=${new Date(Date.now()+24*n*60*60*1e3).toUTCString()}`,a=r?`domain=${r}`:"";document.cookie=[o,"path=/",i,a,"SameSite=Lax"].join("; ")}),void 0)}function R(t,e){return new Promise(((n,r)=>{let o=!1;null==e||e.then((()=>o=!0),(()=>o=!0));("function"==typeof t?R(Promise.resolve(),e).then(t):t).then((t=>{o||n(t)}),(t=>{o||r(t)}))}))}function M(t){return`${t.origin}${t.pathname.endsWith("/")?t.pathname:`${t.pathname}/`}web/`}const I=/The document is sandboxed and lacks the 'allow-same-origin' flag/,j=/The operation is insecure/,O=/Forbidden in a sandboxed document without the 'allow-same-origin' flag/;function z(t){if("function"==typeof TextDecoder){const e=(new TextDecoder).decode(t);if(e)return e}const e=k(t);return decodeURIComponent(escape(String.fromCharCode.apply(null,e)))}function F(t,e){return void 0===t?[e]:p(t)?function(t,e){let n,r=!1;f(t)?(r=!0,n=it(t.value)):n=it(t);const o=[];for(const t of n){const e=E(t,"endpoints");e&&o.push(M(e))}r||o.push(e);return o}(t,e):function(t){if(!t||"object"!=typeof t)return!1;const e=t;if("string"!=typeof e.__type__||694409711!==(n=e.__type__,d(ut(n))))return!1;var n;return(void 0===e.script||p(e.script))&&(void 0===e.helper||p(e.helper))&&(void 0===e.ingress||p(e.ingress))}(t)?function(t,e,n){if(void 0===t)return[e];let r,o=!1;f(t)?(o=!0,r=it(t.value)):r=it(t);const i=[];for(const t of r){const e=E(t,n);e&&i.push(e.href)}return o||i.push(e),i}(t.script,e,"script"):null}function W(t){return t>=q&&t<q+10||t===X}function B({level:t,message:e}){"error"===t?console.error(e):"warning"===t?console.warn(e):console.log(e)}function K(n,o,i){const a=i instanceof u?i.code:null;if(a===t||a===e)return{action:"exclude",delay:0};if(a===c)return{action:"exclude",delay:"backoff"};if(a===r){return{action:"postpone",delay:Date.now()-n.getTime()<50?0:"backoff"}}return{action:"postpone",delay:"backoff"}}const N=34,q=48,H=101,J=117,X=45,G=/*#__PURE__*/new Uint8Array([110,J,108,108]),Q=/*#__PURE__*/new Uint8Array([116,114,J,H]),V=/*#__PURE__*/new Uint8Array([102,97,108,115,H]),Y={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},Z=/*#__PURE__*/(()=>{const t=new Uint8Array(128);for(const[e,n]of Object.entries(Y))t[n.charCodeAt(0)]=e.charCodeAt(0);return t})();function tt(t){return"string"==typeof t||Array.isArray(t)&&t.every((t=>"string"==typeof t))}function et(t){let e,n;const{picked:f,rest:d}=function(t,e){const n={},r={};for(const[o,i]of Object.entries(t))e.includes(o)?n[o]=i:r[o]=i;return{picked:n,rest:r}}(t,["apiKey"]),{apiKey:h}=f;if(!h)throw new u(s[o],o);if("string"!=typeof h)throw new u(s[i],i);var p,w;const m=function(t,e){const n=F(t,"https://fpnpmcdn.net/");if(null===n)throw new u(s[a],a);return n.map((t=>function(t,e){const n=new URL(t,window.location.href),r=n.pathname;return n.pathname=`${r}${r.endsWith("/")?"":"/"}v4/${encodeURIComponent(e)}`,n.search=`?ci=jsl/${encodeURIComponent("4.0.1")}`,n.href}(t,e)))}(function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(p=t,w="endpoints")?p[w]:void 0,h),[y,g]=function(){const t=[],e=()=>{t.push({time:new Date,state:document.visibilityState})},n=(r=document,o="visibilitychange",i=e,r.addEventListener(o,i,a),()=>r.removeEventListener(o,i,a));var r,o,i,a;return e(),[t,n]}();const v=async function(){try{const[t,n]=await l(m,S),r=await t.start({...d,ldi:{attempts:n,visibilityStates:y}});return e=r,r}catch(t){throw n=function(t){return t instanceof u&&t.code===c?new u(s[r],r):t}(t),n}finally{g()}}();return{async get(t){if(e)return e.get(t);if(n)throw n;return(await v).get(t)},async collect(t){if(e)return e.collect(t);if(n)throw n;return(await v).collect(t)}}}async function nt(t,e,n,r,o,i,a){if(void 0===t)return;let c=t;for(let t=0;t<e;++t){const e=new Date;let s,u;try{s=await R((()=>n(c,t,a)),a)}catch(t){u=t,i.failedAttempts.push({level:0,endpoint:c,error:t})}if(s){const t=r(s);if("result"in t){i.result=t.result;break}if(i.failedAttempts.push({level:1,endpoint:c,error:t.error}),t.stop)break}const l=o(e,s,u);if(!l)break;await R(ot(l[1]),a),c=l[0]}}function rt(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}function ot(t,e){return new Promise((n=>function(t,e,...n){const r=Date.now()+e;let o=0;const i=()=>{o=setTimeout((()=>{Date.now()<r?i():t(...n)}),r-Date.now())};return i(),()=>clearTimeout(o)}(n,t,e)))}function it(t){return y(t)?t:[t]}const at=[3,13],ct=[3,14],st=9;function ut(t){const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>127)return(new TextEncoder).encode(t);e[n]=r}return e}function lt(t){return{__type__:A,value:t}}const ft=function(t,e={}){const{storageKeyPrefix:r=x,do:o}=e;try{const e=T(t);null!==e?(e.visitorToken&&(i=e.visitorToken,b(a=`${r}t`,i,365),function(t,e){var n;try{null===(n=null===localStorage||void 0===localStorage?void 0:localStorage.setItem)||void 0===n||n.call(localStorage,t,e)}catch(t){}}(a,i)),e.notifications.forEach(B),w(o,(()=>({e:25,result:{response:e}})))):w(o,(()=>({e:25,result:{error:new Error("Failed to decode response")}})))}catch(t){throw w(o,(()=>({e:25,result:{error:t instanceof Error?t:new Error(String(t))}}))),new u(s[n],n)}var i,a};var dt={start:et,handleAgentData:ft,isFingerprintError:rt,withoutDefault:lt};export{dt as default,ft as handleAgentData,rt as isFingerprintError,et as start,lt as withoutDefault};
|