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