UNPKG

@fingerprintjs/fingerprintjs-pro

Version:

Fingerprint JavaScript agent

6 lines (4 loc) 12.5 kB
/** * Fingerprint v3.12.9 - Copyright (c) FingerprintJS, Inc, 2026 (https://fingerprint.com) */ function e(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}function t(e){return new Promise(((t,n)=>{if(function(e){if(!URL.prototype)return;try{return new URL(e,location.href),!1}catch(t){if(t instanceof Error&&"TypeError"===t.name)return!0;throw t}}(e))throw new Error(H);const r=document.createElement("script"),o=()=>{var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=()=>{o(),t()},r.onerror=()=>{o(),n(new Error(Pe))},r.async=!0,r.src=e,i.appendChild(r)}))}function n({level:e,message:t}){"error"===e?console.error(t):"warning"===e?console.warn(t):console.log(t)}function r(e,t){if(e.arr.length<t){const n=new Uint8Array(Math.max(2*e.arr.length,t));n.set(e.arr),e.arr=n}}function o(){return function(){var e,t;const n=window;return["buildID"in navigator,"MozAppearance"in(null!==(t=null===(e=document.documentElement)||void 0===e?void 0:e.style)&&void 0!==t?t:{}),"onmozfullscreenchange"in n,"mozInnerScreenX"in n,"CSSMozDocumentRule"in n,"CanvasCaptureMediaStream"in n].reduce(((e,t)=>e+(t?1:0)),0)>=4}()}function i(e){const t={len:0,arr:new Uint8Array(128)},n=fe(e);let r=0;const o=()=>(u(),n[r]===p?i():a(n[r])?c():d(M)?(r+=M.length,null):d(x)?(r+=x.length,!0):d(k)?(r+=k.length,!1):n[r]===U?s():n[r]===C?l():f()),i=()=>{for(t.len=0;r++,n[r]!==p;){if(n[r]===m){if(r++,n[r]===A){const e=parseInt(pe(n.subarray(r+1,r+5)),16);ke(t,h(String.fromCharCode(e))),r+=4;continue}const e=V[n[r]];if(e){le(t,e);continue}return f()}if(void 0===n[r])return f();le(t,n[r])}return r++,pe(function(e){return e.arr.subarray(0,e.len)}(t))},c=()=>{const e=r;for(;n[r]===b||n[r]===y||n[r]===N||n[r]===S||a(n[r]);)r++;return Number(pe(n.subarray(e,r)))},s=()=>{const e=[];for(r++;;){if(u(),n[r]===P){r++;break}if(e.length){if(n[r]!==_)return f();r++}e.push(o())}return e},l=()=>{const e={};let t=!0;for(r++;;){if(u(),n[r]===L){r++;break}if(!t){if(n[r]!==_)return f();r++,u()}if(n[r]!==p)return f();const c=i();if(u(),n[r]!==O)return f();r++,Object.defineProperty(e,c,{value:o(),configurable:!0,enumerable:!0,writable:!0}),t=!1}return e},u=()=>{for(;n[r]===w||n[r]===v||n[r]===g||n[r]===I;)r++},d=e=>{for(let t=0;t<e.length;t++)if(n[r+t]!==e[t])return!1;return!0},f=()=>{throw new SyntaxError("Unexpected "+(r<n.length?`byte ${r}`:"end"))},R=o();return u(),void 0!==n[r]&&f(),R}function c(e,t){return function(e,t,n){const r=()=>{throw new Error("Invalid data")},o=fe(e);o.length<t.length+2&&r();for(let d=0;d<t.length;++d)re(o[1+d],o[0])!==t[d]&&r();const i=1+t.length,c=re(o[i],o[0]);o.length<i+1+c+n&&r();const a=i+1+c,s=a+n,l=new ArrayBuffer(o.length-s),u=new Uint8Array(l);for(let d=0;d<u.length;++d)u[d]=o[s+d]^o[a+d%n];return l}(e,t?Ee:Re,he)}function a(e){return e>=T&&e<T+10||e===D}function s(e,t,n,r){Le((()=>{const o=`${e}=${t}`,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 l(e,t){!function(e,t,n){if(se((t=>{!function(e,t){s(e,"",-1,t)}(e,t)})),n<0)return;se((r=>(s(e,t,n,r),function(e){return Le((()=>{const t=`${e}=`;for(const e of document.cookie.split(";")){let n=0;for(;" "===e[n]&&n<e.length;)++n;if(e.indexOf(t)===n)return e.slice(n+t.length)}}),void 0)}(e)===t)))}(t,e,365),function(e,t){var n;try{null===(n=null===localStorage||void 0===localStorage?void 0:localStorage.setItem)||void 0===n||n.call(localStorage,e,t)}catch(r){}}(t,e)}function u(){const e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n;const r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(Ce);return n}const d={default:"endpoint"},f={default:"tlsEndpoint"},R="_vid";function E(e,t){return(Array.isArray(e)?e:[e]).map((e=>function(e,t){const n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(e=>"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n(Ue):e))}(String(e),t)))}function h(e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);if(r>127)return(new TextEncoder).encode(e);t[n]=r}return t}const p=34,_=44,O=58,w=32,I=9,g=13,v=10,m=92,T=48,y=101,A=117,N=69,S=43,D=45,b=46,U=91,P=93,C=123,L=125,M=/*#__PURE__*/new Uint8Array([110,A,108,108]),x=/*#__PURE__*/new Uint8Array([116,114,A,y]),k=/*#__PURE__*/new Uint8Array([102,97,108,115,y]),K={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},V=/*#__PURE__*/(()=>{const e=new Uint8Array(128);for(const[t,n]of Object.entries(K))e[n.charCodeAt(0)]=t.charCodeAt(0);return e})(),B="Client timeout",F="Network connection error",G="Network request aborted",j="Response cannot be parsed",$="Blocked by CSP",H="The endpoint parameter is not a valid URL",q="Handle on demand agent data error",X=/*#__PURE__*/_e("WrongRegion"),Y=/*#__PURE__*/_e("SubscriptionNotActive"),W=/*#__PURE__*/_e("UnsupportedVersion"),z=/*#__PURE__*/_e("InstallationMethodRestricted"),J=/*#__PURE__*/_e("HostnameRestricted"),Q=/*#__PURE__*/_e("IntegrationFailed"),Z=/*#__PURE__*/_e("NetworkRestricted"),ee=/*#__PURE__*/_e("InvalidProxyIntegrationSecret"),te=/*#__PURE__*/_e("InvalidProxyIntegrationHeaders"),ne=/*#__PURE__*/_e("ProxyIntegrationSecretEnvironmentMismatch");function re(e,t){return(e-t+256)%256}function oe(e){return function(e,t,n,r){const o=document,i="securitypolicyviolation";let c;const a=t=>{const n=new URL(e,location.href),{blockedURI:r}=t;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(c=t,s())};o.addEventListener(i,a);const s=()=>o.removeEventListener(i,a);return null==r||r.then(s,s),Promise.resolve().then(t).then((e=>(s(),e)),(e=>new Promise((e=>{const t=new MessageChannel;t.port1.onmessage=()=>e(),t.port2.postMessage(null)})).then((()=>{if(s(),c)return n(c);throw e}))))}(e,(()=>t(e)),(()=>{throw new Error($)})).then(u)}const ie=/The document is sandboxed and lacks the 'allow-same-origin' flag/,ce=/The operation is insecure/,ae=/Forbidden in a sandboxed document without the 'allow-same-origin' flag/;function se(e){const t=location.hostname,n=o();(function(e,t){let n=e.length-("."===e.slice(-1)?1:0);do{if(n=n>0?e.lastIndexOf(".",n-1):-1,!0===t(e.slice(n+1)))return!0}while(n>=0);return!1})(t,(r=>{if(!n||!/^([^.]{1,3}\.)*[^.]+\.?$/.test(r)||r===t)return e(r)}))||e()}function le(e,t){r(e,e.len+1),e.arr[e.len++]=t}function ue(t){var n,r;const{picked:o,rest:i}=function(e,t){const n={},r={};for(const[o,i]of Object.entries(e))t.includes(o)?n[o]=i:r[o]=i;return{picked:n,rest:r}}(t,["scriptUrlPattern","token","apiKey"]),c=o.token,a=null!==(n=o.apiKey)&&void 0!==n?n:c,s=null!==(r=e(t,"scriptUrlPattern"))&&void 0!==r?r:Me.scriptUrl,[l,u]=function(){const e=[],t=()=>{e.push({time:new Date,state:document.visibilityState})},n=(r=document,o="visibilitychange",i=t,r.addEventListener(o,i,c),()=>r.removeEventListener(o,i,c));var r,o,i,c;return t(),[e,n]}();return Promise.resolve().then((()=>{if(!a||"string"!=typeof a)throw new Error(we);return function(e,t){const n=[],r=5,[o,i]=function(e){const t=function(e){const t=[...e];return{current:()=>t[0],postpone(){const e=t.shift();void 0!==e&&t.push(e)},exclude(){t.shift()}}}(e),n=function(e,t){let n=0;return()=>Math.random()*Math.min(t,e*Math.pow(2,n++))}(100,3e3),r=new Set;return[t.current(),(e,o)=>{let i;const c=o instanceof Error?o.message:"";if(c===$||c===H)t.exclude(),i=0;else if(c===Ce)t.exclude();else if(c===Pe){const n=Date.now()-e.getTime()<50,o=t.current();o&&n&&!r.has(o)&&(r.add(o),i=0),t.postpone()}else t.postpone();const a=t.current();return void 0===a?void 0:[a,null!=i?i:e.getTime()+n()-Date.now()]}]}(e);let c;if(void 0===o)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const a=e=>{const o=new Date,s=t=>n.push({url:e,startedAt:o,finishedAt:new Date,error:t}),l=t(e);return l.then((()=>s()),s),l.catch((e=>{if(null!=c||(c=e),n.length>=r)throw c;const t=i(o,e);if(!t)throw c;const[s,l]=t;return(u=l,new Promise((e=>setTimeout(e,u)))).then((()=>a(s)));var u}))};return a(o).then((e=>[e,n]))}(E(s,a),oe)})).catch((e=>{throw u(),function(e){return e instanceof Error&&e.message===Ce?new Error(Pe):e}(e)})).then((([e,t])=>(u(),e.load({...i,ldi:{attempts:t,visibilityStates:l}}))))}function de(e,t,...n){e&&async function(e,t){try{await e()}catch(n){return console.error(n),t}}((()=>{const r=t(...n);void 0!==r&&e(r)}))}function fe(e){return e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}const Re=[3,13],Ee=[3,14],he=9;function pe(e){if("function"==typeof TextDecoder){const t=(new TextDecoder).decode(e);if(t)return t}const t=fe(e);return decodeURIComponent(escape(String.fromCharCode.apply(null,t)))}function _e(e){let t="";for(let n=0;n<e.length;++n)if(n>0){const r=e[n].toLowerCase();r!==e[n]?t+=` ${r}`:t+=e[n]}else t+=e[n].toUpperCase();return t}const Oe=function(e,t={}){const{storageKey:r=R,do:o}=t;try{const t=function(e){const t=function(e){const t=atob(e),n=t.length,r=new Uint8Array(n);for(let o=0;o<n;o++)r[o]=t.charCodeAt(o);return r}(e);let n=t;try{n=c(t,!1)}catch(r){}try{return i(n)}catch(o){}return null}(e);null!==t?(t.visitorToken&&l(t.visitorToken,`${r}_t`),null==(a=t.notifications)||a.forEach(n),de(o,(()=>({e:25,result:{response:t}})))):de(o,(()=>({e:25,result:{error:new Error("Failed to decode response")}})))}catch(s){throw de(o,(()=>({e:25,result:{error:s instanceof Error?s:new Error(String(s))}}))),function(e,t,n){const r=new Error(e);return void 0!==t&&(r.requestId=t),void 0!==n&&(r.raw=n),r}(q,void 0,s)}var a},we="API key required",Ie="API key not found",ge="API key expired",ve="Request cannot be parsed",me="Request failed",Te="Request failed to process",ye="Too many requests, rate limit exceeded",Ae="Not available for this origin",Ne="Not available with restricted header",Se=we,De=Ie,be=ge;var Ue="3.12.9";const Pe="Failed to load the JS script of the agent",Ce="9319";function Le(e,t){try{document.cookie}catch(n){if(function(e){if(!(e instanceof DOMException))return!1;const t=e.message;return ie.test(t)||ce.test(t)||ae.test(t)}(n))return t;throw n}return e()}const Me={scriptUrl:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js"},xe=Me.scriptUrl;function ke(e,t){r(e,e.len+t.length),e.arr.set(t,e.len),e.len+=t.length}var Ke={load:ue,defaultScriptUrlPattern:xe,ERROR_SCRIPT_LOAD_FAIL:Pe,ERROR_API_KEY_EXPIRED:ge,ERROR_API_KEY_INVALID:Ie,ERROR_API_KEY_MISSING:we,ERROR_BAD_REQUEST_FORMAT:ve,ERROR_BAD_RESPONSE_FORMAT:j,ERROR_CLIENT_TIMEOUT:B,ERROR_CSP_BLOCK:$,ERROR_FORBIDDEN_ENDPOINT:J,ERROR_FORBIDDEN_HEADER:Ne,ERROR_FORBIDDEN_ORIGIN:Ae,ERROR_GENERAL_SERVER_FAILURE:me,ERROR_HANDLE_AGENT_DATA:q,ERROR_INSTALLATION_METHOD_RESTRICTED:z,ERROR_INTEGRATION_FAILURE:Q,ERROR_INVALID_ENDPOINT:H,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:te,ERROR_INVALID_PROXY_INTEGRATION_SECRET:ee,ERROR_NETWORK_ABORT:G,ERROR_NETWORK_CONNECTION:F,ERROR_NETWORK_RESTRICTED:Z,ERROR_PROXY_INTEGRATION_SECRET_ENVIRONMENT_MISMATCH:ne,ERROR_RATE_LIMIT:ye,ERROR_SERVER_TIMEOUT:Te,ERROR_SUBSCRIPTION_NOT_ACTIVE:Y,ERROR_TOKEN_EXPIRED:be,ERROR_TOKEN_INVALID:De,ERROR_TOKEN_MISSING:Se,ERROR_UNSUPPORTED_VERSION:W,ERROR_WRONG_REGION:X,defaultEndpoint:d,defaultTlsEndpoint:f,handleAgentData:Oe};export{ge as ERROR_API_KEY_EXPIRED,Ie as ERROR_API_KEY_INVALID,we as ERROR_API_KEY_MISSING,ve as ERROR_BAD_REQUEST_FORMAT,j as ERROR_BAD_RESPONSE_FORMAT,B as ERROR_CLIENT_TIMEOUT,$ as ERROR_CSP_BLOCK,J as ERROR_FORBIDDEN_ENDPOINT,Ne as ERROR_FORBIDDEN_HEADER,Ae as ERROR_FORBIDDEN_ORIGIN,me as ERROR_GENERAL_SERVER_FAILURE,q as ERROR_HANDLE_AGENT_DATA,z as ERROR_INSTALLATION_METHOD_RESTRICTED,Q as ERROR_INTEGRATION_FAILURE,H as ERROR_INVALID_ENDPOINT,te as ERROR_INVALID_PROXY_INTEGRATION_HEADERS,ee as ERROR_INVALID_PROXY_INTEGRATION_SECRET,G as ERROR_NETWORK_ABORT,F as ERROR_NETWORK_CONNECTION,Z as ERROR_NETWORK_RESTRICTED,ne as ERROR_PROXY_INTEGRATION_SECRET_ENVIRONMENT_MISMATCH,ye as ERROR_RATE_LIMIT,Pe as ERROR_SCRIPT_LOAD_FAIL,Te as ERROR_SERVER_TIMEOUT,Y as ERROR_SUBSCRIPTION_NOT_ACTIVE,be as ERROR_TOKEN_EXPIRED,De as ERROR_TOKEN_INVALID,Se as ERROR_TOKEN_MISSING,W as ERROR_UNSUPPORTED_VERSION,X as ERROR_WRONG_REGION,Ke as default,d as defaultEndpoint,xe as defaultScriptUrlPattern,f as defaultTlsEndpoint,Oe as handleAgentData,ue as load};