@serge-ai/js 0.2.1 → 0.2.2
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/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/s.js +1 -1
- package/package.json +3 -7
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';function j(){let e=[],t="unknown";try{navigator.webdriver===!0&&e.push("webdriver");}catch{e.push("webdriver_error");}("__playwright__binding__"in window||"__pwInitScripts"in window)&&(e.push("playwright_globals"),t="browser_use");let r=[{selector:'[id^="claude-agent-"]',signal:"claude_dom",platform:"claude"},{selector:'[id^="comet-agent-"]',signal:"comet_dom",platform:"perplexity"},{selector:'[id^="perplexity-comet-"]',signal:"comet_dom_alt",platform:"perplexity"},{selector:'[id^="chatgpt-atlas-"]',signal:"atlas_dom",platform:"chatgpt"},{selector:'[id^="openai-atlas-"]',signal:"atlas_dom_alt",platform:"chatgpt"}];for(let i of r)document.querySelector(i.selector)&&(e.push(i.signal),t=i.platform);let n=navigator.userAgent;return /PerplexityBot\/|Perplexity-User\//i.test(n)?(e.push("perplexity_ua"),t="perplexity"):/OAI-SearchBot\//i.test(n)?(e.push("oai_searchbot_ua"),t="chatgpt"):/ChatGPT-User\//i.test(n)?(e.push("chatgpt_user_ua"),t="chatgpt"):/Operator\//i.test(n)?(e.push("operator_ua"),t="chatgpt"):/GPTBot\//i.test(n)?(e.push("gptbot_ua"),t="chatgpt"):/ClaudeBot\//i.test(n)?(e.push("claudebot_ua"),t="claude"):/Claude-User\/|claude-web\//i.test(n)?(e.push("claude_user_ua"),t="claude"):/Claude-SearchBot\//i.test(n)?(e.push("claude_searchbot_ua"),t="claude"):/Claude-Code\//i.test(n)?(e.push("claude_code_ua"),t="claude"):/Google-Extended\//i.test(n)?(e.push("google_extended_ua"),t="gemini"):/Applebot-Extended\//i.test(n)?(e.push("applebot_extended_ua"),t="apple"):/Applebot\//i.test(n)?(e.push("applebot_ua"),t="apple"):/Meta-ExternalAgent\/|Meta-ExternalFetcher\//i.test(n)?(e.push("meta_externalagent_ua"),t="meta"):/bingbot\/|BingPreview\//i.test(n)&&(e.push("bingbot_ua"),t="bing"),e.length===0?null:{platform:t,confidence:.99,signals:e}}function W(){let e=[],t=0,r;try{let n=navigator.userAgent,i=/Macintosh|Mac OS X/i.test(n),s=/Windows NT/i.test(n),a=navigator.userAgentData;a&&a.platform==="Linux"&&(i||s)&&(e.push("platform_mismatch"),t+=.5,r="chatgpt");}catch{}try{let n=navigator.userAgent,i=navigator.userAgentData;if(i&&Array.isArray(i.brands)&&/Chrome\//i.test(n)){let s=i.brands.map(u=>u.brand),a=s.some(u=>/Google Chrome/i.test(u)),c=s.some(u=>/Chromium/i.test(u));!a&&c&&(e.push("brand_list_anomaly"),t+=.4,r=r??"chatgpt");}}catch{}try{let n=navigator.userAgent;/Mobile|Android|iPhone/i.test(n)&&navigator.maxTouchPoints===0&&(e.push("touch_mismatch"),t+=.3);}catch{}try{(screen.width===0||screen.height===0)&&(e.push("zero_screen"),t+=.4),screen.colorDepth===0&&(e.push("zero_colordepth"),t+=.3);}catch{}try{window.innerWidth>0&&window.outerWidth>0&&window.outerWidth<window.innerWidth&&(e.push("viewport_mismatch"),t+=.2);}catch{}try{"Notification"in window||(e.push("missing_notification_api"),t+=.2);}catch{}try{let n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(i){let s=i.getExtension("WEBGL_debug_renderer_info"),c=String(s?i.getParameter(s.UNMASKED_RENDERER_WEBGL):i.getParameter(i.RENDERER)).toLowerCase();(c.includes("swiftshader")||c.includes("swangle")||c.includes("llvmpipe")||c.includes("mesa offscreen"))&&(e.push("webgl_software_renderer"),t+=.45);}else i===null&&(e.push("missing_webgl"),t+=.25);}catch{}try{let n=document.createElement("canvas");n.width=32,n.height=16;let i=n.getContext("2d");if(i){i.textBaseline="top",i.font='13px "Arial"',i.fillStyle="#f60",i.fillRect(0,0,32,16),i.fillStyle="#069",i.fillText("serge:ag",1,1);let s=i.getImageData(0,0,32,16).data,a=0,c=0;for(let d=0;d<s.length;d+=4)s[d]===0&&s[d+1]===0&&s[d+2]===0&&a++,s[d]>c&&(c=s[d]);a/(s.length/4)>.95&&c<20&&(e.push("canvas_flat_render"),t+=.2);}}catch{}try{let n=navigator.userAgentData;if(n&&typeof n.getHighEntropyValues=="function"){let i=navigator.userAgent,s=/Chrome\/(\d+)/i.exec(i);if(s&&Array.isArray(n.brands)){let a=Number(s[1]),c=n.brands.find(u=>/Chrome/i.test(u.brand)&&!/Chromium/i.test(u.brand));if(c&&typeof c.version=="string"){let u=Number(c.version.split(".")[0]);Number.isFinite(a)&&Number.isFinite(u)&&Math.abs(a-u)>2&&(e.push("ua_version_major_mismatch"),t+=.35);}}}}catch{}return t=Math.min(t,1),{signals:e,score:t,platform:r}}var o=null,L=false,b=null;function me(){return {mouseMoveCount:0,scrollEvents:0,clickCount:0,clickTimestamps:[],anyHoverDetected:false,firstInteractionMs:null,pageLoadTime:performance.now()}}function G(){o&&o.mouseMoveCount++;}function K(){o&&(o.anyHoverDetected=true);}function q(){o&&o.scrollEvents++;}function z(){if(!o)return;let e=performance.now();o.clickCount++,o.clickTimestamps.push(e),o.firstInteractionMs===null&&(o.firstInteractionMs=e-o.pageLoadTime);}function he(){document.removeEventListener("mousemove",G),document.removeEventListener("mouseover",K),document.removeEventListener("scroll",q),document.removeEventListener("click",z),L=false;}function ve(){if(!o)return {signals:[],score:0};let e=[],t=0;if(o.mouseMoveCount===0&&o.clickCount>0&&(e.push("no_mouse"),t+=.3),o.firstInteractionMs!==null&&o.firstInteractionMs<100&&(e.push("fast_interaction"),t+=.4),o.clickCount>0&&!o.anyHoverDetected&&o.mouseMoveCount===0&&(e.push("no_hover"),t+=.2),o.clickTimestamps.length>=3){let r=[];for(let a=1;a<o.clickTimestamps.length;a++)r.push(o.clickTimestamps[a]-o.clickTimestamps[a-1]);let n=r.reduce((a,c)=>a+c,0)/r.length,i=r.reduce((a,c)=>a+(c-n)**2,0)/r.length;(n>0?Math.sqrt(i)/n:0)<.1&&(e.push("mechanical_timing"),t+=.3);}return o.scrollEvents===0&&document.documentElement.scrollHeight>window.innerHeight*2&&o.clickCount>0&&(e.push("no_scroll"),t+=.15),{signals:e,score:Math.min(t,1)}}function $(e=5e3){return L?new Promise(t=>{b=t;}):(o=me(),L=true,document.addEventListener("mousemove",G,{passive:true}),document.addEventListener("mouseover",K,{passive:true}),document.addEventListener("scroll",q,{passive:true}),document.addEventListener("click",z,{passive:true}),new Promise(t=>{b=t,setTimeout(()=>{he();let r=ve();o=null,b&&(b(r),b=null);},e);}))}function Y(){let e=j();if(e&&e.confidence>=.85)return {immediate:e,refine:Promise.resolve(e)};let t=W(),r=[...e?.signals??[],...t.signals],n=e?.platform??t.platform??"unknown",i=Math.min((e?.confidence??0)*.5+t.score,1),s={platform:n,confidence:i,signals:[...r]};if(i>=.85)return {immediate:s,refine:Promise.resolve(s)};let a=$(5e3).then(c=>{let u=[...r,...c.signals],d=c.score,I;return i>0?I=Math.min(.3*i+.7*d,1):I=d*.85,{platform:n,confidence:I,signals:u,behavioralScore:d}});return {immediate:s,refine:a}}var g="";function D(e){g=e;}function m(e){if(!g)return;let t=JSON.stringify(e);J(t).catch(()=>{setTimeout(()=>J(t).catch(()=>{}),2e3);});}function J(e){return fetch(g,{method:"POST",body:e,headers:{"Content-Type":"text/plain"},keepalive:true,credentials:"omit"}).then(t=>{if(!t.ok&&t.status!==429)throw new Error(`HTTP ${t.status}`)})}function F(e){if(!g)return;let t=JSON.stringify(e);if(typeof fetchLater=="function")try{fetchLater(g,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},activateAfter:0,credentials:"omit"});return}catch{}try{navigator.sendBeacon(g,t);}catch{fetch(g,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},keepalive:true,credentials:"omit"}).catch(()=>{});}}var M="",X=null;function Q(e){if(X=e,M=location.pathname+location.search,"navigation"in window)window.navigation.addEventListener("navigatesuccess",()=>{_();});else {let t=history.pushState,r=history.replaceState;history.pushState=function(...n){t.apply(this,n),_();},history.replaceState=function(...n){r.apply(this,n),_();},window.addEventListener("popstate",_);}window.addEventListener("pageshow",t=>{t.persisted&&_();});}function _(){let e=location.pathname+location.search;e!==M&&(M=e,X?.());}var ye="serge_signals";function P(e){let t=`${e}/api/v1/signals`;fetch(t,{method:"GET",credentials:"omit"}).then(r=>{if(r.ok)return r.json()}).then(r=>{if(r)try{let n={data:r,fetchedAt:Date.now()};sessionStorage.setItem(ye,JSON.stringify(n));}catch{}}).catch(()=>{});}var Z="_serge_consent",h=null;function be(){try{let e=window.localStorage.getItem(Z);if(e==="granted"||e==="denied")return e}catch{}return "unknown"}function _e(e){if(e!=="unknown")try{window.localStorage.setItem(Z,e);}catch{}}function ee(){return h!==null||(h=be()),h}function te(e){return e!=="granted"&&e!=="denied"&&e!=="unknown"?h??"unknown":(h=e,_e(e),e)}var re="serge-traps-root",ie="serge_trap_config";var we=new Set(["div","span","p","a","button","select","option","h1","h2","h3","h4","h5","h6","ul","li","img","form","input","label"]),Se=new Set(["role","aria-label","aria-hidden","aria-describedby","aria-labelledby","tabindex","href","target","rel","type","name","value","placeholder","src","alt","data-trap","data-trap-kind","data-trap-token"]),Ee=new Set(["position","top","left","right","bottom","width","height","overflow","visibility","opacity","clip-path","clip","pointer-events","color","background","background-color","font-size"]),Ce=new Set(["click","change","submit","mouseover","focus"]);function oe(e){let t=String(e.tag??"").toLowerCase();if(!we.has(t))return null;let r=document.createElement(t);if(e.attrs&&typeof e.attrs=="object"){for(let[n,i]of Object.entries(e.attrs))if(Se.has(n)&&typeof i=="string")try{r.setAttribute(n,i);}catch{}}if(e.style&&typeof e.style=="object"){for(let[n,i]of Object.entries(e.style))if(Ee.has(n)&&typeof i=="string")try{r.style.setProperty(n,i);}catch{}}if(typeof e.text=="string"&&r.appendChild(document.createTextNode(e.text)),Array.isArray(e.children))for(let n of e.children){let i=oe(n);i&&r.appendChild(i);}return r}function Te(e){try{if("sendBeacon"in navigator){navigator.sendBeacon(e);return}}catch{}try{fetch(e,{method:"GET",mode:"no-cors",credentials:"omit",keepalive:!0}).catch(()=>{});}catch{}}function Ae(e,t){for(let r of t.triggers){if(!Ce.has(r.event))continue;let n=e.querySelector(r.selector);n&&n.addEventListener(r.event,()=>{Te(t.trapUrl);},{once:true,capture:true});}}function xe(){try{let e=sessionStorage.getItem(ie);if(!e)return null;let t=JSON.parse(e);return Date.now()-t.fetchedAt>36e5?null:t.data}catch{return null}}function ke(e){try{let t={data:e,fetchedAt:Date.now()};sessionStorage.setItem(ie,JSON.stringify(t));}catch{}}function O(){return !!document.getElementById(re)}function ne(e){if(O()||!e||!Array.isArray(e.traps)||e.traps.length===0)return;let t=document.createElement("div");t.id=re,t.setAttribute("aria-hidden","true"),t.setAttribute("data-serge-traps","1"),t.style.setProperty("position","absolute"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip-path","inset(50%)");for(let r of e.traps){let n=oe(r.root);n&&(n.setAttribute("data-serge-trap-id",String(r.id??"")),n.setAttribute("data-serge-trap-kind",String(r.kind??"")),t.appendChild(n),Ae(n,r));}document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>document.body&&document.body.appendChild(t),{once:true});}function B(e){if(e.enabled===false||O())return;let t=xe();t&&ne(t);let r=`${e.apiBase}/api/v1/trap-config?s=${encodeURIComponent(e.siteId)}&sid=${encodeURIComponent(e.sessionId)}`;fetch(r,{method:"GET",credentials:"omit"}).then(n=>n.ok?n.json():null).then(n=>{!n||!Array.isArray(n.traps)||(ke(n),O()||ne(n));}).catch(()=>{});}var Re=new Set(["access_token","api_key","apikey","auth","authorization","bearer","code","cvc","cvv","email","id_token","jwt","key","oauth_token","one_time_password","otp","password","pin","refresh_token","reset_token","secret","session","sig","signature","ssn","token"]);function se(e){if(!e)return "";if(!e.includes("?"))return e;let t,r=false;try{e.startsWith("/")||!/^[a-z]+:\/\//i.test(e)&&!e.startsWith("//")?(t=new URL(e,"https://placeholder.invalid"),r=!0):t=new URL(e);}catch{return e}if(t.searchParams.size===0)return e;let n=false;for(let i of Array.from(t.searchParams.keys()))Re.has(i.toLowerCase())&&(t.searchParams.delete(i),n=true);return n?r?t.pathname+t.search+t.hash:t.toString():e}var ae="_s_sid",v=null;function Ie(){let e=new Uint8Array(12);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(36).padStart(2,"0")).join("")}function w(){if(v)return v;try{let e=sessionStorage.getItem(ae);if(e)return v=e,e}catch{}v=Ie();try{sessionStorage.setItem(ae,v);}catch{}return v}function N(){let e=Date.now().toString(36),t=new Uint8Array(4);crypto.getRandomValues(t);let r=Array.from(t,n=>n.toString(36).padStart(2,"0")).join("");return `${e}-${r}`}var ce="0.2.1";var A=false,l=null,f=null,E=0,x="",U=0,S=false,p="unknown",y="",V=false;function k(){return l?l.debug?true:!!f&&f.confidence>=.35:false}function R(){return typeof window<"u"&&typeof document<"u"}function ot(e,t={}){if(!R())return;if(!e){t.debug&&console.error("[serge] init(token) requires a token");return}let r=performance.now(),n=(t.apiBase??"https://serge.ai").replace(/\/$/,"");y=n,D(`${n}/api/ingest/snippet`),l={token:e,apiBase:n,debug:t.debug??false,requireConsent:t.requireConsent??false,defaults:t.defaults},A=true,U=performance.now()-r,!(l.requireConsent&&(p=ee(),p==="denied"||p!=="granted"))&&(de(),B({apiBase:n,siteId:e,sessionId:w()}),P(n),document.visibilityState==="hidden"||document.visibilityState==="prerender"?document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&T();},{once:true}):T());}function de(){if(!l)return;let e={s:l.token,sid:w(),eid:N(),ap:"unknown",ac:0,ds:[],et:"init",ts:new Date().toISOString(),u:location.pathname,t:document.title||void 0};m(e);}async function T(){if(!l)return;E=performance.now(),x=location.pathname;let{immediate:e,refine:t}=Y();f=e,(l.debug||e.confidence>=.35)&&(ue(),H(),le());let r=await t;f=r,!l.debug&&e.confidence<.35&&r.confidence>=.35&&(ue(),H(),le());}function le(){V||(V=true,Q(fe),document.addEventListener("visibilitychange",De),window.addEventListener("pagehide",Me));}function C(e,t){if(!l||!f)throw new Error("[serge] tracker not initialized \u2014 call init() first");let r=document.referrer?se(document.referrer):"";return {s:l.token,sid:w(),eid:N(),ap:f.platform,ac:Math.round(f.confidence*100)/100,ds:f.signals,bs:f.behavioralScore!=null?Math.round(f.behavioralScore*100)/100:void 0,et:e,ts:new Date().toISOString(),u:location.pathname,r:r||void 0,t:document.title||void 0,...t}}function ue(){S=false;let e={init_ms:Math.round(U),v:ce,sv:3};l?.defaults&&(e.d=l.defaults),m(C("session_start",{vw:window.innerWidth,vh:window.innerHeight,sw:screen.width,sh:screen.height,ua:navigator.userAgent,p:Pe(),l:navigator.language,_m:e}));}function H(){E=performance.now(),x=location.pathname,m(C("page_view"));}function fe(){if(!k())return;let e=Math.round(performance.now()-E);m(C("route_change",{u:x,tp:e,sd:ge()})),H(),S=false;}function De(){document.visibilityState==="hidden"&&pe();}function Me(){pe();}function pe(){if(S||!k())return;S=true;let e=Math.round(performance.now()-E);F(C("session_end",{tp:e,sd:ge()}));}function ge(){let e=document.documentElement.scrollHeight,t=window.innerHeight;if(e<=t)return 100;let r=window.scrollY||document.documentElement.scrollTop;return Math.min(100,Math.round((r+t)/e*100))}function Pe(){try{return navigator.userAgentData?.platform??navigator.platform??""}catch{return ""}}function st(e,t){!R()||!A||k()&&m(C("semantic_action",{ix:[{t:e,tg:JSON.stringify(t??{}),o:0,ok:true}]}));}function at(e){if(!R())return;let t=p;p=te(e),!(!l||!l.requireConsent)&&t!==p&&p==="granted"&&t!=="granted"&&(y!==""&&P(y),de(),y!==""&&B({apiBase:y,siteId:l.token,sessionId:w()}),document.visibilityState==="hidden"||document.visibilityState==="prerender"?document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&T();},{once:true}):T());}function ct(){!R()||!A||k()&&fe();}function lt(){A=false,l=null,f=null,E=0,x="",U=0,S=false,p="unknown",y="",V=false,D("");}
|
|
1
|
+
'use strict';function j(){let e=[],t="unknown";try{navigator.webdriver===!0&&e.push("webdriver");}catch{e.push("webdriver_error");}("__playwright__binding__"in window||"__pwInitScripts"in window)&&(e.push("playwright_globals"),t="browser_use");let r=[{selector:'[id^="claude-agent-"]',signal:"claude_dom",platform:"claude"},{selector:'[id^="comet-agent-"]',signal:"comet_dom",platform:"perplexity"},{selector:'[id^="perplexity-comet-"]',signal:"comet_dom_alt",platform:"perplexity"},{selector:'[id^="chatgpt-atlas-"]',signal:"atlas_dom",platform:"chatgpt"},{selector:'[id^="openai-atlas-"]',signal:"atlas_dom_alt",platform:"chatgpt"}];for(let i of r)document.querySelector(i.selector)&&(e.push(i.signal),t=i.platform);let n=navigator.userAgent;return /PerplexityBot\/|Perplexity-User\//i.test(n)?(e.push("perplexity_ua"),t="perplexity"):/OAI-SearchBot\//i.test(n)?(e.push("oai_searchbot_ua"),t="chatgpt"):/ChatGPT-User\//i.test(n)?(e.push("chatgpt_user_ua"),t="chatgpt"):/Operator\//i.test(n)?(e.push("operator_ua"),t="chatgpt"):/GPTBot\//i.test(n)?(e.push("gptbot_ua"),t="chatgpt"):/ClaudeBot\//i.test(n)?(e.push("claudebot_ua"),t="claude"):/Claude-User\/|claude-web\//i.test(n)?(e.push("claude_user_ua"),t="claude"):/Claude-SearchBot\//i.test(n)?(e.push("claude_searchbot_ua"),t="claude"):/Claude-Code\//i.test(n)?(e.push("claude_code_ua"),t="claude"):/Google-Extended\//i.test(n)?(e.push("google_extended_ua"),t="gemini"):/Applebot-Extended\//i.test(n)?(e.push("applebot_extended_ua"),t="apple"):/Applebot\//i.test(n)?(e.push("applebot_ua"),t="apple"):/Meta-ExternalAgent\/|Meta-ExternalFetcher\//i.test(n)?(e.push("meta_externalagent_ua"),t="meta"):/bingbot\/|BingPreview\//i.test(n)&&(e.push("bingbot_ua"),t="bing"),e.length===0?null:{platform:t,confidence:.99,signals:e}}function W(){let e=[],t=0,r;try{let n=navigator.userAgent,i=/Macintosh|Mac OS X/i.test(n),s=/Windows NT/i.test(n),a=navigator.userAgentData;a&&a.platform==="Linux"&&(i||s)&&(e.push("platform_mismatch"),t+=.5,r="chatgpt");}catch{}try{let n=navigator.userAgent,i=navigator.userAgentData;if(i&&Array.isArray(i.brands)&&/Chrome\//i.test(n)){let s=i.brands.map(u=>u.brand),a=s.some(u=>/Google Chrome/i.test(u)),c=s.some(u=>/Chromium/i.test(u));!a&&c&&(e.push("brand_list_anomaly"),t+=.4,r=r??"chatgpt");}}catch{}try{let n=navigator.userAgent;/Mobile|Android|iPhone/i.test(n)&&navigator.maxTouchPoints===0&&(e.push("touch_mismatch"),t+=.3);}catch{}try{(screen.width===0||screen.height===0)&&(e.push("zero_screen"),t+=.4),screen.colorDepth===0&&(e.push("zero_colordepth"),t+=.3);}catch{}try{window.innerWidth>0&&window.outerWidth>0&&window.outerWidth<window.innerWidth&&(e.push("viewport_mismatch"),t+=.2);}catch{}try{"Notification"in window||(e.push("missing_notification_api"),t+=.2);}catch{}try{let n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(i){let s=i.getExtension("WEBGL_debug_renderer_info"),c=String(s?i.getParameter(s.UNMASKED_RENDERER_WEBGL):i.getParameter(i.RENDERER)).toLowerCase();(c.includes("swiftshader")||c.includes("swangle")||c.includes("llvmpipe")||c.includes("mesa offscreen"))&&(e.push("webgl_software_renderer"),t+=.45);}else i===null&&(e.push("missing_webgl"),t+=.25);}catch{}try{let n=document.createElement("canvas");n.width=32,n.height=16;let i=n.getContext("2d");if(i){i.textBaseline="top",i.font='13px "Arial"',i.fillStyle="#f60",i.fillRect(0,0,32,16),i.fillStyle="#069",i.fillText("serge:ag",1,1);let s=i.getImageData(0,0,32,16).data,a=0,c=0;for(let d=0;d<s.length;d+=4)s[d]===0&&s[d+1]===0&&s[d+2]===0&&a++,s[d]>c&&(c=s[d]);a/(s.length/4)>.95&&c<20&&(e.push("canvas_flat_render"),t+=.2);}}catch{}try{let n=navigator.userAgentData;if(n&&typeof n.getHighEntropyValues=="function"){let i=navigator.userAgent,s=/Chrome\/(\d+)/i.exec(i);if(s&&Array.isArray(n.brands)){let a=Number(s[1]),c=n.brands.find(u=>/Chrome/i.test(u.brand)&&!/Chromium/i.test(u.brand));if(c&&typeof c.version=="string"){let u=Number(c.version.split(".")[0]);Number.isFinite(a)&&Number.isFinite(u)&&Math.abs(a-u)>2&&(e.push("ua_version_major_mismatch"),t+=.35);}}}}catch{}return t=Math.min(t,1),{signals:e,score:t,platform:r}}var o=null,L=false,b=null;function me(){return {mouseMoveCount:0,scrollEvents:0,clickCount:0,clickTimestamps:[],anyHoverDetected:false,firstInteractionMs:null,pageLoadTime:performance.now()}}function G(){o&&o.mouseMoveCount++;}function K(){o&&(o.anyHoverDetected=true);}function q(){o&&o.scrollEvents++;}function z(){if(!o)return;let e=performance.now();o.clickCount++,o.clickTimestamps.push(e),o.firstInteractionMs===null&&(o.firstInteractionMs=e-o.pageLoadTime);}function he(){document.removeEventListener("mousemove",G),document.removeEventListener("mouseover",K),document.removeEventListener("scroll",q),document.removeEventListener("click",z),L=false;}function ve(){if(!o)return {signals:[],score:0};let e=[],t=0;if(o.mouseMoveCount===0&&o.clickCount>0&&(e.push("no_mouse"),t+=.3),o.firstInteractionMs!==null&&o.firstInteractionMs<100&&(e.push("fast_interaction"),t+=.4),o.clickCount>0&&!o.anyHoverDetected&&o.mouseMoveCount===0&&(e.push("no_hover"),t+=.2),o.clickTimestamps.length>=3){let r=[];for(let a=1;a<o.clickTimestamps.length;a++)r.push(o.clickTimestamps[a]-o.clickTimestamps[a-1]);let n=r.reduce((a,c)=>a+c,0)/r.length,i=r.reduce((a,c)=>a+(c-n)**2,0)/r.length;(n>0?Math.sqrt(i)/n:0)<.1&&(e.push("mechanical_timing"),t+=.3);}return o.scrollEvents===0&&document.documentElement.scrollHeight>window.innerHeight*2&&o.clickCount>0&&(e.push("no_scroll"),t+=.15),{signals:e,score:Math.min(t,1)}}function $(e=5e3){return L?new Promise(t=>{b=t;}):(o=me(),L=true,document.addEventListener("mousemove",G,{passive:true}),document.addEventListener("mouseover",K,{passive:true}),document.addEventListener("scroll",q,{passive:true}),document.addEventListener("click",z,{passive:true}),new Promise(t=>{b=t,setTimeout(()=>{he();let r=ve();o=null,b&&(b(r),b=null);},e);}))}function Y(){let e=j();if(e&&e.confidence>=.85)return {immediate:e,refine:Promise.resolve(e)};let t=W(),r=[...e?.signals??[],...t.signals],n=e?.platform??t.platform??"unknown",i=Math.min((e?.confidence??0)*.5+t.score,1),s={platform:n,confidence:i,signals:[...r]};if(i>=.85)return {immediate:s,refine:Promise.resolve(s)};let a=$(5e3).then(c=>{let u=[...r,...c.signals],d=c.score,I;return i>0?I=Math.min(.3*i+.7*d,1):I=d*.85,{platform:n,confidence:I,signals:u,behavioralScore:d}});return {immediate:s,refine:a}}var g="";function D(e){g=e;}function m(e){if(!g)return;let t=JSON.stringify(e);J(t).catch(()=>{setTimeout(()=>J(t).catch(()=>{}),2e3);});}function J(e){return fetch(g,{method:"POST",body:e,headers:{"Content-Type":"text/plain"},keepalive:true,credentials:"omit"}).then(t=>{if(!t.ok&&t.status!==429)throw new Error(`HTTP ${t.status}`)})}function F(e){if(!g)return;let t=JSON.stringify(e);if(typeof fetchLater=="function")try{fetchLater(g,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},activateAfter:0,credentials:"omit"});return}catch{}try{navigator.sendBeacon(g,t);}catch{fetch(g,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},keepalive:true,credentials:"omit"}).catch(()=>{});}}var M="",X=null;function Q(e){if(X=e,M=location.pathname+location.search,"navigation"in window)window.navigation.addEventListener("navigatesuccess",()=>{_();});else {let t=history.pushState,r=history.replaceState;history.pushState=function(...n){t.apply(this,n),_();},history.replaceState=function(...n){r.apply(this,n),_();},window.addEventListener("popstate",_);}window.addEventListener("pageshow",t=>{t.persisted&&_();});}function _(){let e=location.pathname+location.search;e!==M&&(M=e,X?.());}var ye="serge_signals";function P(e){let t=`${e}/api/v1/signals`;fetch(t,{method:"GET",credentials:"omit"}).then(r=>{if(r.ok)return r.json()}).then(r=>{if(r)try{let n={data:r,fetchedAt:Date.now()};sessionStorage.setItem(ye,JSON.stringify(n));}catch{}}).catch(()=>{});}var Z="_serge_consent",h=null;function be(){try{let e=window.localStorage.getItem(Z);if(e==="granted"||e==="denied")return e}catch{}return "unknown"}function _e(e){if(e!=="unknown")try{window.localStorage.setItem(Z,e);}catch{}}function ee(){return h!==null||(h=be()),h}function te(e){return e!=="granted"&&e!=="denied"&&e!=="unknown"?h??"unknown":(h=e,_e(e),e)}var re="serge-traps-root",ie="serge_trap_config";var we=new Set(["div","span","p","a","button","select","option","h1","h2","h3","h4","h5","h6","ul","li","img","form","input","label"]),Se=new Set(["role","aria-label","aria-hidden","aria-describedby","aria-labelledby","tabindex","href","target","rel","type","name","value","placeholder","src","alt","data-trap","data-trap-kind","data-trap-token"]),Ee=new Set(["position","top","left","right","bottom","width","height","overflow","visibility","opacity","clip-path","clip","pointer-events","color","background","background-color","font-size"]),Ce=new Set(["click","change","submit","mouseover","focus"]);function oe(e){let t=String(e.tag??"").toLowerCase();if(!we.has(t))return null;let r=document.createElement(t);if(e.attrs&&typeof e.attrs=="object"){for(let[n,i]of Object.entries(e.attrs))if(Se.has(n)&&typeof i=="string")try{r.setAttribute(n,i);}catch{}}if(e.style&&typeof e.style=="object"){for(let[n,i]of Object.entries(e.style))if(Ee.has(n)&&typeof i=="string")try{r.style.setProperty(n,i);}catch{}}if(typeof e.text=="string"&&r.appendChild(document.createTextNode(e.text)),Array.isArray(e.children))for(let n of e.children){let i=oe(n);i&&r.appendChild(i);}return r}function Te(e){try{if("sendBeacon"in navigator){navigator.sendBeacon(e);return}}catch{}try{fetch(e,{method:"GET",mode:"no-cors",credentials:"omit",keepalive:!0}).catch(()=>{});}catch{}}function Ae(e,t){for(let r of t.triggers){if(!Ce.has(r.event))continue;let n=e.querySelector(r.selector);n&&n.addEventListener(r.event,()=>{Te(t.trapUrl);},{once:true,capture:true});}}function xe(){try{let e=sessionStorage.getItem(ie);if(!e)return null;let t=JSON.parse(e);return Date.now()-t.fetchedAt>36e5?null:t.data}catch{return null}}function ke(e){try{let t={data:e,fetchedAt:Date.now()};sessionStorage.setItem(ie,JSON.stringify(t));}catch{}}function O(){return !!document.getElementById(re)}function ne(e){if(O()||!e||!Array.isArray(e.traps)||e.traps.length===0)return;let t=document.createElement("div");t.id=re,t.setAttribute("aria-hidden","true"),t.setAttribute("data-serge-traps","1"),t.style.setProperty("position","absolute"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip-path","inset(50%)");for(let r of e.traps){let n=oe(r.root);n&&(n.setAttribute("data-serge-trap-id",String(r.id??"")),n.setAttribute("data-serge-trap-kind",String(r.kind??"")),t.appendChild(n),Ae(n,r));}document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>document.body&&document.body.appendChild(t),{once:true});}function B(e){if(e.enabled===false||O())return;let t=xe();t&&ne(t);let r=`${e.apiBase}/api/v1/trap-config?s=${encodeURIComponent(e.siteId)}&sid=${encodeURIComponent(e.sessionId)}`;fetch(r,{method:"GET",credentials:"omit"}).then(n=>n.ok?n.json():null).then(n=>{!n||!Array.isArray(n.traps)||(ke(n),O()||ne(n));}).catch(()=>{});}var Re=new Set(["access_token","api_key","apikey","auth","authorization","bearer","code","cvc","cvv","email","id_token","jwt","key","oauth_token","one_time_password","otp","password","pin","refresh_token","reset_token","secret","session","sig","signature","ssn","token"]);function se(e){if(!e)return "";if(!e.includes("?"))return e;let t,r=false;try{e.startsWith("/")||!/^[a-z]+:\/\//i.test(e)&&!e.startsWith("//")?(t=new URL(e,"https://placeholder.invalid"),r=!0):t=new URL(e);}catch{return e}if(t.searchParams.size===0)return e;let n=false;for(let i of Array.from(t.searchParams.keys()))Re.has(i.toLowerCase())&&(t.searchParams.delete(i),n=true);return n?r?t.pathname+t.search+t.hash:t.toString():e}var ae="_s_sid",v=null;function Ie(){let e=new Uint8Array(12);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(36).padStart(2,"0")).join("")}function w(){if(v)return v;try{let e=sessionStorage.getItem(ae);if(e)return v=e,e}catch{}v=Ie();try{sessionStorage.setItem(ae,v);}catch{}return v}function N(){let e=Date.now().toString(36),t=new Uint8Array(4);crypto.getRandomValues(t);let r=Array.from(t,n=>n.toString(36).padStart(2,"0")).join("");return `${e}-${r}`}var ce="0.2.2";var A=false,l=null,f=null,E=0,x="",U=0,S=false,p="unknown",y="",V=false;function k(){return l?l.debug?true:!!f&&f.confidence>=.35:false}function R(){return typeof window<"u"&&typeof document<"u"}function ot(e,t={}){if(!R())return;if(!e){t.debug&&console.error("[serge] init(token) requires a token");return}let r=performance.now(),n=(t.apiBase??"https://serge.ai").replace(/\/$/,"");y=n,D(`${n}/api/ingest/snippet`),l={token:e,apiBase:n,debug:t.debug??false,requireConsent:t.requireConsent??false,defaults:t.defaults},A=true,U=performance.now()-r,!(l.requireConsent&&(p=ee(),p==="denied"||p!=="granted"))&&(de(),B({apiBase:n,siteId:e,sessionId:w()}),P(n),document.visibilityState==="hidden"||document.visibilityState==="prerender"?document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&T();},{once:true}):T());}function de(){if(!l)return;let e={s:l.token,sid:w(),eid:N(),ap:"unknown",ac:0,ds:[],et:"init",ts:new Date().toISOString(),u:location.pathname,t:document.title||void 0};m(e);}async function T(){if(!l)return;E=performance.now(),x=location.pathname;let{immediate:e,refine:t}=Y();f=e,(l.debug||e.confidence>=.35)&&(ue(),H(),le());let r=await t;f=r,!l.debug&&e.confidence<.35&&r.confidence>=.35&&(ue(),H(),le());}function le(){V||(V=true,Q(fe),document.addEventListener("visibilitychange",De),window.addEventListener("pagehide",Me));}function C(e,t){if(!l||!f)throw new Error("[serge] tracker not initialized \u2014 call init() first");let r=document.referrer?se(document.referrer):"";return {s:l.token,sid:w(),eid:N(),ap:f.platform,ac:Math.round(f.confidence*100)/100,ds:f.signals,bs:f.behavioralScore!=null?Math.round(f.behavioralScore*100)/100:void 0,et:e,ts:new Date().toISOString(),u:location.pathname,r:r||void 0,t:document.title||void 0,...t}}function ue(){S=false;let e={init_ms:Math.round(U),v:ce,sv:3};l?.defaults&&(e.d=l.defaults),m(C("session_start",{vw:window.innerWidth,vh:window.innerHeight,sw:screen.width,sh:screen.height,ua:navigator.userAgent,p:Pe(),l:navigator.language,_m:e}));}function H(){E=performance.now(),x=location.pathname,m(C("page_view"));}function fe(){if(!k())return;let e=Math.round(performance.now()-E);m(C("route_change",{u:x,tp:e,sd:ge()})),H(),S=false;}function De(){document.visibilityState==="hidden"&&pe();}function Me(){pe();}function pe(){if(S||!k())return;S=true;let e=Math.round(performance.now()-E);F(C("session_end",{tp:e,sd:ge()}));}function ge(){let e=document.documentElement.scrollHeight,t=window.innerHeight;if(e<=t)return 100;let r=window.scrollY||document.documentElement.scrollTop;return Math.min(100,Math.round((r+t)/e*100))}function Pe(){try{return navigator.userAgentData?.platform??navigator.platform??""}catch{return ""}}function st(e,t){!R()||!A||k()&&m(C("semantic_action",{ix:[{t:e,tg:JSON.stringify(t??{}),o:0,ok:true}]}));}function at(e){if(!R())return;let t=p;p=te(e),!(!l||!l.requireConsent)&&t!==p&&p==="granted"&&t!=="granted"&&(y!==""&&P(y),de(),y!==""&&B({apiBase:y,siteId:l.token,sessionId:w()}),document.visibilityState==="hidden"||document.visibilityState==="prerender"?document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&T();},{once:true}):T());}function ct(){!R()||!A||k()&&fe();}function lt(){A=false,l=null,f=null,E=0,x="",U=0,S=false,p="unknown",y="",V=false,D("");}
|
|
2
2
|
exports.SDK_VERSION=ce;exports._resetForTesting=lt;exports.consent=at;exports.init=ot;exports.pageview=ct;exports.track=st;//# sourceMappingURL=index.cjs.map
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function j(){let e=[],t="unknown";try{navigator.webdriver===!0&&e.push("webdriver");}catch{e.push("webdriver_error");}("__playwright__binding__"in window||"__pwInitScripts"in window)&&(e.push("playwright_globals"),t="browser_use");let r=[{selector:'[id^="claude-agent-"]',signal:"claude_dom",platform:"claude"},{selector:'[id^="comet-agent-"]',signal:"comet_dom",platform:"perplexity"},{selector:'[id^="perplexity-comet-"]',signal:"comet_dom_alt",platform:"perplexity"},{selector:'[id^="chatgpt-atlas-"]',signal:"atlas_dom",platform:"chatgpt"},{selector:'[id^="openai-atlas-"]',signal:"atlas_dom_alt",platform:"chatgpt"}];for(let i of r)document.querySelector(i.selector)&&(e.push(i.signal),t=i.platform);let n=navigator.userAgent;return /PerplexityBot\/|Perplexity-User\//i.test(n)?(e.push("perplexity_ua"),t="perplexity"):/OAI-SearchBot\//i.test(n)?(e.push("oai_searchbot_ua"),t="chatgpt"):/ChatGPT-User\//i.test(n)?(e.push("chatgpt_user_ua"),t="chatgpt"):/Operator\//i.test(n)?(e.push("operator_ua"),t="chatgpt"):/GPTBot\//i.test(n)?(e.push("gptbot_ua"),t="chatgpt"):/ClaudeBot\//i.test(n)?(e.push("claudebot_ua"),t="claude"):/Claude-User\/|claude-web\//i.test(n)?(e.push("claude_user_ua"),t="claude"):/Claude-SearchBot\//i.test(n)?(e.push("claude_searchbot_ua"),t="claude"):/Claude-Code\//i.test(n)?(e.push("claude_code_ua"),t="claude"):/Google-Extended\//i.test(n)?(e.push("google_extended_ua"),t="gemini"):/Applebot-Extended\//i.test(n)?(e.push("applebot_extended_ua"),t="apple"):/Applebot\//i.test(n)?(e.push("applebot_ua"),t="apple"):/Meta-ExternalAgent\/|Meta-ExternalFetcher\//i.test(n)?(e.push("meta_externalagent_ua"),t="meta"):/bingbot\/|BingPreview\//i.test(n)&&(e.push("bingbot_ua"),t="bing"),e.length===0?null:{platform:t,confidence:.99,signals:e}}function W(){let e=[],t=0,r;try{let n=navigator.userAgent,i=/Macintosh|Mac OS X/i.test(n),s=/Windows NT/i.test(n),a=navigator.userAgentData;a&&a.platform==="Linux"&&(i||s)&&(e.push("platform_mismatch"),t+=.5,r="chatgpt");}catch{}try{let n=navigator.userAgent,i=navigator.userAgentData;if(i&&Array.isArray(i.brands)&&/Chrome\//i.test(n)){let s=i.brands.map(u=>u.brand),a=s.some(u=>/Google Chrome/i.test(u)),c=s.some(u=>/Chromium/i.test(u));!a&&c&&(e.push("brand_list_anomaly"),t+=.4,r=r??"chatgpt");}}catch{}try{let n=navigator.userAgent;/Mobile|Android|iPhone/i.test(n)&&navigator.maxTouchPoints===0&&(e.push("touch_mismatch"),t+=.3);}catch{}try{(screen.width===0||screen.height===0)&&(e.push("zero_screen"),t+=.4),screen.colorDepth===0&&(e.push("zero_colordepth"),t+=.3);}catch{}try{window.innerWidth>0&&window.outerWidth>0&&window.outerWidth<window.innerWidth&&(e.push("viewport_mismatch"),t+=.2);}catch{}try{"Notification"in window||(e.push("missing_notification_api"),t+=.2);}catch{}try{let n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(i){let s=i.getExtension("WEBGL_debug_renderer_info"),c=String(s?i.getParameter(s.UNMASKED_RENDERER_WEBGL):i.getParameter(i.RENDERER)).toLowerCase();(c.includes("swiftshader")||c.includes("swangle")||c.includes("llvmpipe")||c.includes("mesa offscreen"))&&(e.push("webgl_software_renderer"),t+=.45);}else i===null&&(e.push("missing_webgl"),t+=.25);}catch{}try{let n=document.createElement("canvas");n.width=32,n.height=16;let i=n.getContext("2d");if(i){i.textBaseline="top",i.font='13px "Arial"',i.fillStyle="#f60",i.fillRect(0,0,32,16),i.fillStyle="#069",i.fillText("serge:ag",1,1);let s=i.getImageData(0,0,32,16).data,a=0,c=0;for(let d=0;d<s.length;d+=4)s[d]===0&&s[d+1]===0&&s[d+2]===0&&a++,s[d]>c&&(c=s[d]);a/(s.length/4)>.95&&c<20&&(e.push("canvas_flat_render"),t+=.2);}}catch{}try{let n=navigator.userAgentData;if(n&&typeof n.getHighEntropyValues=="function"){let i=navigator.userAgent,s=/Chrome\/(\d+)/i.exec(i);if(s&&Array.isArray(n.brands)){let a=Number(s[1]),c=n.brands.find(u=>/Chrome/i.test(u.brand)&&!/Chromium/i.test(u.brand));if(c&&typeof c.version=="string"){let u=Number(c.version.split(".")[0]);Number.isFinite(a)&&Number.isFinite(u)&&Math.abs(a-u)>2&&(e.push("ua_version_major_mismatch"),t+=.35);}}}}catch{}return t=Math.min(t,1),{signals:e,score:t,platform:r}}var o=null,L=false,b=null;function me(){return {mouseMoveCount:0,scrollEvents:0,clickCount:0,clickTimestamps:[],anyHoverDetected:false,firstInteractionMs:null,pageLoadTime:performance.now()}}function G(){o&&o.mouseMoveCount++;}function K(){o&&(o.anyHoverDetected=true);}function q(){o&&o.scrollEvents++;}function z(){if(!o)return;let e=performance.now();o.clickCount++,o.clickTimestamps.push(e),o.firstInteractionMs===null&&(o.firstInteractionMs=e-o.pageLoadTime);}function he(){document.removeEventListener("mousemove",G),document.removeEventListener("mouseover",K),document.removeEventListener("scroll",q),document.removeEventListener("click",z),L=false;}function ve(){if(!o)return {signals:[],score:0};let e=[],t=0;if(o.mouseMoveCount===0&&o.clickCount>0&&(e.push("no_mouse"),t+=.3),o.firstInteractionMs!==null&&o.firstInteractionMs<100&&(e.push("fast_interaction"),t+=.4),o.clickCount>0&&!o.anyHoverDetected&&o.mouseMoveCount===0&&(e.push("no_hover"),t+=.2),o.clickTimestamps.length>=3){let r=[];for(let a=1;a<o.clickTimestamps.length;a++)r.push(o.clickTimestamps[a]-o.clickTimestamps[a-1]);let n=r.reduce((a,c)=>a+c,0)/r.length,i=r.reduce((a,c)=>a+(c-n)**2,0)/r.length;(n>0?Math.sqrt(i)/n:0)<.1&&(e.push("mechanical_timing"),t+=.3);}return o.scrollEvents===0&&document.documentElement.scrollHeight>window.innerHeight*2&&o.clickCount>0&&(e.push("no_scroll"),t+=.15),{signals:e,score:Math.min(t,1)}}function $(e=5e3){return L?new Promise(t=>{b=t;}):(o=me(),L=true,document.addEventListener("mousemove",G,{passive:true}),document.addEventListener("mouseover",K,{passive:true}),document.addEventListener("scroll",q,{passive:true}),document.addEventListener("click",z,{passive:true}),new Promise(t=>{b=t,setTimeout(()=>{he();let r=ve();o=null,b&&(b(r),b=null);},e);}))}function Y(){let e=j();if(e&&e.confidence>=.85)return {immediate:e,refine:Promise.resolve(e)};let t=W(),r=[...e?.signals??[],...t.signals],n=e?.platform??t.platform??"unknown",i=Math.min((e?.confidence??0)*.5+t.score,1),s={platform:n,confidence:i,signals:[...r]};if(i>=.85)return {immediate:s,refine:Promise.resolve(s)};let a=$(5e3).then(c=>{let u=[...r,...c.signals],d=c.score,I;return i>0?I=Math.min(.3*i+.7*d,1):I=d*.85,{platform:n,confidence:I,signals:u,behavioralScore:d}});return {immediate:s,refine:a}}var g="";function D(e){g=e;}function m(e){if(!g)return;let t=JSON.stringify(e);J(t).catch(()=>{setTimeout(()=>J(t).catch(()=>{}),2e3);});}function J(e){return fetch(g,{method:"POST",body:e,headers:{"Content-Type":"text/plain"},keepalive:true,credentials:"omit"}).then(t=>{if(!t.ok&&t.status!==429)throw new Error(`HTTP ${t.status}`)})}function F(e){if(!g)return;let t=JSON.stringify(e);if(typeof fetchLater=="function")try{fetchLater(g,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},activateAfter:0,credentials:"omit"});return}catch{}try{navigator.sendBeacon(g,t);}catch{fetch(g,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},keepalive:true,credentials:"omit"}).catch(()=>{});}}var M="",X=null;function Q(e){if(X=e,M=location.pathname+location.search,"navigation"in window)window.navigation.addEventListener("navigatesuccess",()=>{_();});else {let t=history.pushState,r=history.replaceState;history.pushState=function(...n){t.apply(this,n),_();},history.replaceState=function(...n){r.apply(this,n),_();},window.addEventListener("popstate",_);}window.addEventListener("pageshow",t=>{t.persisted&&_();});}function _(){let e=location.pathname+location.search;e!==M&&(M=e,X?.());}var ye="serge_signals";function P(e){let t=`${e}/api/v1/signals`;fetch(t,{method:"GET",credentials:"omit"}).then(r=>{if(r.ok)return r.json()}).then(r=>{if(r)try{let n={data:r,fetchedAt:Date.now()};sessionStorage.setItem(ye,JSON.stringify(n));}catch{}}).catch(()=>{});}var Z="_serge_consent",h=null;function be(){try{let e=window.localStorage.getItem(Z);if(e==="granted"||e==="denied")return e}catch{}return "unknown"}function _e(e){if(e!=="unknown")try{window.localStorage.setItem(Z,e);}catch{}}function ee(){return h!==null||(h=be()),h}function te(e){return e!=="granted"&&e!=="denied"&&e!=="unknown"?h??"unknown":(h=e,_e(e),e)}var re="serge-traps-root",ie="serge_trap_config";var we=new Set(["div","span","p","a","button","select","option","h1","h2","h3","h4","h5","h6","ul","li","img","form","input","label"]),Se=new Set(["role","aria-label","aria-hidden","aria-describedby","aria-labelledby","tabindex","href","target","rel","type","name","value","placeholder","src","alt","data-trap","data-trap-kind","data-trap-token"]),Ee=new Set(["position","top","left","right","bottom","width","height","overflow","visibility","opacity","clip-path","clip","pointer-events","color","background","background-color","font-size"]),Ce=new Set(["click","change","submit","mouseover","focus"]);function oe(e){let t=String(e.tag??"").toLowerCase();if(!we.has(t))return null;let r=document.createElement(t);if(e.attrs&&typeof e.attrs=="object"){for(let[n,i]of Object.entries(e.attrs))if(Se.has(n)&&typeof i=="string")try{r.setAttribute(n,i);}catch{}}if(e.style&&typeof e.style=="object"){for(let[n,i]of Object.entries(e.style))if(Ee.has(n)&&typeof i=="string")try{r.style.setProperty(n,i);}catch{}}if(typeof e.text=="string"&&r.appendChild(document.createTextNode(e.text)),Array.isArray(e.children))for(let n of e.children){let i=oe(n);i&&r.appendChild(i);}return r}function Te(e){try{if("sendBeacon"in navigator){navigator.sendBeacon(e);return}}catch{}try{fetch(e,{method:"GET",mode:"no-cors",credentials:"omit",keepalive:!0}).catch(()=>{});}catch{}}function Ae(e,t){for(let r of t.triggers){if(!Ce.has(r.event))continue;let n=e.querySelector(r.selector);n&&n.addEventListener(r.event,()=>{Te(t.trapUrl);},{once:true,capture:true});}}function xe(){try{let e=sessionStorage.getItem(ie);if(!e)return null;let t=JSON.parse(e);return Date.now()-t.fetchedAt>36e5?null:t.data}catch{return null}}function ke(e){try{let t={data:e,fetchedAt:Date.now()};sessionStorage.setItem(ie,JSON.stringify(t));}catch{}}function O(){return !!document.getElementById(re)}function ne(e){if(O()||!e||!Array.isArray(e.traps)||e.traps.length===0)return;let t=document.createElement("div");t.id=re,t.setAttribute("aria-hidden","true"),t.setAttribute("data-serge-traps","1"),t.style.setProperty("position","absolute"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip-path","inset(50%)");for(let r of e.traps){let n=oe(r.root);n&&(n.setAttribute("data-serge-trap-id",String(r.id??"")),n.setAttribute("data-serge-trap-kind",String(r.kind??"")),t.appendChild(n),Ae(n,r));}document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>document.body&&document.body.appendChild(t),{once:true});}function B(e){if(e.enabled===false||O())return;let t=xe();t&&ne(t);let r=`${e.apiBase}/api/v1/trap-config?s=${encodeURIComponent(e.siteId)}&sid=${encodeURIComponent(e.sessionId)}`;fetch(r,{method:"GET",credentials:"omit"}).then(n=>n.ok?n.json():null).then(n=>{!n||!Array.isArray(n.traps)||(ke(n),O()||ne(n));}).catch(()=>{});}var Re=new Set(["access_token","api_key","apikey","auth","authorization","bearer","code","cvc","cvv","email","id_token","jwt","key","oauth_token","one_time_password","otp","password","pin","refresh_token","reset_token","secret","session","sig","signature","ssn","token"]);function se(e){if(!e)return "";if(!e.includes("?"))return e;let t,r=false;try{e.startsWith("/")||!/^[a-z]+:\/\//i.test(e)&&!e.startsWith("//")?(t=new URL(e,"https://placeholder.invalid"),r=!0):t=new URL(e);}catch{return e}if(t.searchParams.size===0)return e;let n=false;for(let i of Array.from(t.searchParams.keys()))Re.has(i.toLowerCase())&&(t.searchParams.delete(i),n=true);return n?r?t.pathname+t.search+t.hash:t.toString():e}var ae="_s_sid",v=null;function Ie(){let e=new Uint8Array(12);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(36).padStart(2,"0")).join("")}function w(){if(v)return v;try{let e=sessionStorage.getItem(ae);if(e)return v=e,e}catch{}v=Ie();try{sessionStorage.setItem(ae,v);}catch{}return v}function N(){let e=Date.now().toString(36),t=new Uint8Array(4);crypto.getRandomValues(t);let r=Array.from(t,n=>n.toString(36).padStart(2,"0")).join("");return `${e}-${r}`}var ce="0.2.1";var A=false,l=null,f=null,E=0,x="",U=0,S=false,p="unknown",y="",V=false;function k(){return l?l.debug?true:!!f&&f.confidence>=.35:false}function R(){return typeof window<"u"&&typeof document<"u"}function ot(e,t={}){if(!R())return;if(!e){t.debug&&console.error("[serge] init(token) requires a token");return}let r=performance.now(),n=(t.apiBase??"https://serge.ai").replace(/\/$/,"");y=n,D(`${n}/api/ingest/snippet`),l={token:e,apiBase:n,debug:t.debug??false,requireConsent:t.requireConsent??false,defaults:t.defaults},A=true,U=performance.now()-r,!(l.requireConsent&&(p=ee(),p==="denied"||p!=="granted"))&&(de(),B({apiBase:n,siteId:e,sessionId:w()}),P(n),document.visibilityState==="hidden"||document.visibilityState==="prerender"?document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&T();},{once:true}):T());}function de(){if(!l)return;let e={s:l.token,sid:w(),eid:N(),ap:"unknown",ac:0,ds:[],et:"init",ts:new Date().toISOString(),u:location.pathname,t:document.title||void 0};m(e);}async function T(){if(!l)return;E=performance.now(),x=location.pathname;let{immediate:e,refine:t}=Y();f=e,(l.debug||e.confidence>=.35)&&(ue(),H(),le());let r=await t;f=r,!l.debug&&e.confidence<.35&&r.confidence>=.35&&(ue(),H(),le());}function le(){V||(V=true,Q(fe),document.addEventListener("visibilitychange",De),window.addEventListener("pagehide",Me));}function C(e,t){if(!l||!f)throw new Error("[serge] tracker not initialized \u2014 call init() first");let r=document.referrer?se(document.referrer):"";return {s:l.token,sid:w(),eid:N(),ap:f.platform,ac:Math.round(f.confidence*100)/100,ds:f.signals,bs:f.behavioralScore!=null?Math.round(f.behavioralScore*100)/100:void 0,et:e,ts:new Date().toISOString(),u:location.pathname,r:r||void 0,t:document.title||void 0,...t}}function ue(){S=false;let e={init_ms:Math.round(U),v:ce,sv:3};l?.defaults&&(e.d=l.defaults),m(C("session_start",{vw:window.innerWidth,vh:window.innerHeight,sw:screen.width,sh:screen.height,ua:navigator.userAgent,p:Pe(),l:navigator.language,_m:e}));}function H(){E=performance.now(),x=location.pathname,m(C("page_view"));}function fe(){if(!k())return;let e=Math.round(performance.now()-E);m(C("route_change",{u:x,tp:e,sd:ge()})),H(),S=false;}function De(){document.visibilityState==="hidden"&&pe();}function Me(){pe();}function pe(){if(S||!k())return;S=true;let e=Math.round(performance.now()-E);F(C("session_end",{tp:e,sd:ge()}));}function ge(){let e=document.documentElement.scrollHeight,t=window.innerHeight;if(e<=t)return 100;let r=window.scrollY||document.documentElement.scrollTop;return Math.min(100,Math.round((r+t)/e*100))}function Pe(){try{return navigator.userAgentData?.platform??navigator.platform??""}catch{return ""}}function st(e,t){!R()||!A||k()&&m(C("semantic_action",{ix:[{t:e,tg:JSON.stringify(t??{}),o:0,ok:true}]}));}function at(e){if(!R())return;let t=p;p=te(e),!(!l||!l.requireConsent)&&t!==p&&p==="granted"&&t!=="granted"&&(y!==""&&P(y),de(),y!==""&&B({apiBase:y,siteId:l.token,sessionId:w()}),document.visibilityState==="hidden"||document.visibilityState==="prerender"?document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&T();},{once:true}):T());}function ct(){!R()||!A||k()&&fe();}function lt(){A=false,l=null,f=null,E=0,x="",U=0,S=false,p="unknown",y="",V=false,D("");}
|
|
1
|
+
function j(){let e=[],t="unknown";try{navigator.webdriver===!0&&e.push("webdriver");}catch{e.push("webdriver_error");}("__playwright__binding__"in window||"__pwInitScripts"in window)&&(e.push("playwright_globals"),t="browser_use");let r=[{selector:'[id^="claude-agent-"]',signal:"claude_dom",platform:"claude"},{selector:'[id^="comet-agent-"]',signal:"comet_dom",platform:"perplexity"},{selector:'[id^="perplexity-comet-"]',signal:"comet_dom_alt",platform:"perplexity"},{selector:'[id^="chatgpt-atlas-"]',signal:"atlas_dom",platform:"chatgpt"},{selector:'[id^="openai-atlas-"]',signal:"atlas_dom_alt",platform:"chatgpt"}];for(let i of r)document.querySelector(i.selector)&&(e.push(i.signal),t=i.platform);let n=navigator.userAgent;return /PerplexityBot\/|Perplexity-User\//i.test(n)?(e.push("perplexity_ua"),t="perplexity"):/OAI-SearchBot\//i.test(n)?(e.push("oai_searchbot_ua"),t="chatgpt"):/ChatGPT-User\//i.test(n)?(e.push("chatgpt_user_ua"),t="chatgpt"):/Operator\//i.test(n)?(e.push("operator_ua"),t="chatgpt"):/GPTBot\//i.test(n)?(e.push("gptbot_ua"),t="chatgpt"):/ClaudeBot\//i.test(n)?(e.push("claudebot_ua"),t="claude"):/Claude-User\/|claude-web\//i.test(n)?(e.push("claude_user_ua"),t="claude"):/Claude-SearchBot\//i.test(n)?(e.push("claude_searchbot_ua"),t="claude"):/Claude-Code\//i.test(n)?(e.push("claude_code_ua"),t="claude"):/Google-Extended\//i.test(n)?(e.push("google_extended_ua"),t="gemini"):/Applebot-Extended\//i.test(n)?(e.push("applebot_extended_ua"),t="apple"):/Applebot\//i.test(n)?(e.push("applebot_ua"),t="apple"):/Meta-ExternalAgent\/|Meta-ExternalFetcher\//i.test(n)?(e.push("meta_externalagent_ua"),t="meta"):/bingbot\/|BingPreview\//i.test(n)&&(e.push("bingbot_ua"),t="bing"),e.length===0?null:{platform:t,confidence:.99,signals:e}}function W(){let e=[],t=0,r;try{let n=navigator.userAgent,i=/Macintosh|Mac OS X/i.test(n),s=/Windows NT/i.test(n),a=navigator.userAgentData;a&&a.platform==="Linux"&&(i||s)&&(e.push("platform_mismatch"),t+=.5,r="chatgpt");}catch{}try{let n=navigator.userAgent,i=navigator.userAgentData;if(i&&Array.isArray(i.brands)&&/Chrome\//i.test(n)){let s=i.brands.map(u=>u.brand),a=s.some(u=>/Google Chrome/i.test(u)),c=s.some(u=>/Chromium/i.test(u));!a&&c&&(e.push("brand_list_anomaly"),t+=.4,r=r??"chatgpt");}}catch{}try{let n=navigator.userAgent;/Mobile|Android|iPhone/i.test(n)&&navigator.maxTouchPoints===0&&(e.push("touch_mismatch"),t+=.3);}catch{}try{(screen.width===0||screen.height===0)&&(e.push("zero_screen"),t+=.4),screen.colorDepth===0&&(e.push("zero_colordepth"),t+=.3);}catch{}try{window.innerWidth>0&&window.outerWidth>0&&window.outerWidth<window.innerWidth&&(e.push("viewport_mismatch"),t+=.2);}catch{}try{"Notification"in window||(e.push("missing_notification_api"),t+=.2);}catch{}try{let n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(i){let s=i.getExtension("WEBGL_debug_renderer_info"),c=String(s?i.getParameter(s.UNMASKED_RENDERER_WEBGL):i.getParameter(i.RENDERER)).toLowerCase();(c.includes("swiftshader")||c.includes("swangle")||c.includes("llvmpipe")||c.includes("mesa offscreen"))&&(e.push("webgl_software_renderer"),t+=.45);}else i===null&&(e.push("missing_webgl"),t+=.25);}catch{}try{let n=document.createElement("canvas");n.width=32,n.height=16;let i=n.getContext("2d");if(i){i.textBaseline="top",i.font='13px "Arial"',i.fillStyle="#f60",i.fillRect(0,0,32,16),i.fillStyle="#069",i.fillText("serge:ag",1,1);let s=i.getImageData(0,0,32,16).data,a=0,c=0;for(let d=0;d<s.length;d+=4)s[d]===0&&s[d+1]===0&&s[d+2]===0&&a++,s[d]>c&&(c=s[d]);a/(s.length/4)>.95&&c<20&&(e.push("canvas_flat_render"),t+=.2);}}catch{}try{let n=navigator.userAgentData;if(n&&typeof n.getHighEntropyValues=="function"){let i=navigator.userAgent,s=/Chrome\/(\d+)/i.exec(i);if(s&&Array.isArray(n.brands)){let a=Number(s[1]),c=n.brands.find(u=>/Chrome/i.test(u.brand)&&!/Chromium/i.test(u.brand));if(c&&typeof c.version=="string"){let u=Number(c.version.split(".")[0]);Number.isFinite(a)&&Number.isFinite(u)&&Math.abs(a-u)>2&&(e.push("ua_version_major_mismatch"),t+=.35);}}}}catch{}return t=Math.min(t,1),{signals:e,score:t,platform:r}}var o=null,L=false,b=null;function me(){return {mouseMoveCount:0,scrollEvents:0,clickCount:0,clickTimestamps:[],anyHoverDetected:false,firstInteractionMs:null,pageLoadTime:performance.now()}}function G(){o&&o.mouseMoveCount++;}function K(){o&&(o.anyHoverDetected=true);}function q(){o&&o.scrollEvents++;}function z(){if(!o)return;let e=performance.now();o.clickCount++,o.clickTimestamps.push(e),o.firstInteractionMs===null&&(o.firstInteractionMs=e-o.pageLoadTime);}function he(){document.removeEventListener("mousemove",G),document.removeEventListener("mouseover",K),document.removeEventListener("scroll",q),document.removeEventListener("click",z),L=false;}function ve(){if(!o)return {signals:[],score:0};let e=[],t=0;if(o.mouseMoveCount===0&&o.clickCount>0&&(e.push("no_mouse"),t+=.3),o.firstInteractionMs!==null&&o.firstInteractionMs<100&&(e.push("fast_interaction"),t+=.4),o.clickCount>0&&!o.anyHoverDetected&&o.mouseMoveCount===0&&(e.push("no_hover"),t+=.2),o.clickTimestamps.length>=3){let r=[];for(let a=1;a<o.clickTimestamps.length;a++)r.push(o.clickTimestamps[a]-o.clickTimestamps[a-1]);let n=r.reduce((a,c)=>a+c,0)/r.length,i=r.reduce((a,c)=>a+(c-n)**2,0)/r.length;(n>0?Math.sqrt(i)/n:0)<.1&&(e.push("mechanical_timing"),t+=.3);}return o.scrollEvents===0&&document.documentElement.scrollHeight>window.innerHeight*2&&o.clickCount>0&&(e.push("no_scroll"),t+=.15),{signals:e,score:Math.min(t,1)}}function $(e=5e3){return L?new Promise(t=>{b=t;}):(o=me(),L=true,document.addEventListener("mousemove",G,{passive:true}),document.addEventListener("mouseover",K,{passive:true}),document.addEventListener("scroll",q,{passive:true}),document.addEventListener("click",z,{passive:true}),new Promise(t=>{b=t,setTimeout(()=>{he();let r=ve();o=null,b&&(b(r),b=null);},e);}))}function Y(){let e=j();if(e&&e.confidence>=.85)return {immediate:e,refine:Promise.resolve(e)};let t=W(),r=[...e?.signals??[],...t.signals],n=e?.platform??t.platform??"unknown",i=Math.min((e?.confidence??0)*.5+t.score,1),s={platform:n,confidence:i,signals:[...r]};if(i>=.85)return {immediate:s,refine:Promise.resolve(s)};let a=$(5e3).then(c=>{let u=[...r,...c.signals],d=c.score,I;return i>0?I=Math.min(.3*i+.7*d,1):I=d*.85,{platform:n,confidence:I,signals:u,behavioralScore:d}});return {immediate:s,refine:a}}var g="";function D(e){g=e;}function m(e){if(!g)return;let t=JSON.stringify(e);J(t).catch(()=>{setTimeout(()=>J(t).catch(()=>{}),2e3);});}function J(e){return fetch(g,{method:"POST",body:e,headers:{"Content-Type":"text/plain"},keepalive:true,credentials:"omit"}).then(t=>{if(!t.ok&&t.status!==429)throw new Error(`HTTP ${t.status}`)})}function F(e){if(!g)return;let t=JSON.stringify(e);if(typeof fetchLater=="function")try{fetchLater(g,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},activateAfter:0,credentials:"omit"});return}catch{}try{navigator.sendBeacon(g,t);}catch{fetch(g,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},keepalive:true,credentials:"omit"}).catch(()=>{});}}var M="",X=null;function Q(e){if(X=e,M=location.pathname+location.search,"navigation"in window)window.navigation.addEventListener("navigatesuccess",()=>{_();});else {let t=history.pushState,r=history.replaceState;history.pushState=function(...n){t.apply(this,n),_();},history.replaceState=function(...n){r.apply(this,n),_();},window.addEventListener("popstate",_);}window.addEventListener("pageshow",t=>{t.persisted&&_();});}function _(){let e=location.pathname+location.search;e!==M&&(M=e,X?.());}var ye="serge_signals";function P(e){let t=`${e}/api/v1/signals`;fetch(t,{method:"GET",credentials:"omit"}).then(r=>{if(r.ok)return r.json()}).then(r=>{if(r)try{let n={data:r,fetchedAt:Date.now()};sessionStorage.setItem(ye,JSON.stringify(n));}catch{}}).catch(()=>{});}var Z="_serge_consent",h=null;function be(){try{let e=window.localStorage.getItem(Z);if(e==="granted"||e==="denied")return e}catch{}return "unknown"}function _e(e){if(e!=="unknown")try{window.localStorage.setItem(Z,e);}catch{}}function ee(){return h!==null||(h=be()),h}function te(e){return e!=="granted"&&e!=="denied"&&e!=="unknown"?h??"unknown":(h=e,_e(e),e)}var re="serge-traps-root",ie="serge_trap_config";var we=new Set(["div","span","p","a","button","select","option","h1","h2","h3","h4","h5","h6","ul","li","img","form","input","label"]),Se=new Set(["role","aria-label","aria-hidden","aria-describedby","aria-labelledby","tabindex","href","target","rel","type","name","value","placeholder","src","alt","data-trap","data-trap-kind","data-trap-token"]),Ee=new Set(["position","top","left","right","bottom","width","height","overflow","visibility","opacity","clip-path","clip","pointer-events","color","background","background-color","font-size"]),Ce=new Set(["click","change","submit","mouseover","focus"]);function oe(e){let t=String(e.tag??"").toLowerCase();if(!we.has(t))return null;let r=document.createElement(t);if(e.attrs&&typeof e.attrs=="object"){for(let[n,i]of Object.entries(e.attrs))if(Se.has(n)&&typeof i=="string")try{r.setAttribute(n,i);}catch{}}if(e.style&&typeof e.style=="object"){for(let[n,i]of Object.entries(e.style))if(Ee.has(n)&&typeof i=="string")try{r.style.setProperty(n,i);}catch{}}if(typeof e.text=="string"&&r.appendChild(document.createTextNode(e.text)),Array.isArray(e.children))for(let n of e.children){let i=oe(n);i&&r.appendChild(i);}return r}function Te(e){try{if("sendBeacon"in navigator){navigator.sendBeacon(e);return}}catch{}try{fetch(e,{method:"GET",mode:"no-cors",credentials:"omit",keepalive:!0}).catch(()=>{});}catch{}}function Ae(e,t){for(let r of t.triggers){if(!Ce.has(r.event))continue;let n=e.querySelector(r.selector);n&&n.addEventListener(r.event,()=>{Te(t.trapUrl);},{once:true,capture:true});}}function xe(){try{let e=sessionStorage.getItem(ie);if(!e)return null;let t=JSON.parse(e);return Date.now()-t.fetchedAt>36e5?null:t.data}catch{return null}}function ke(e){try{let t={data:e,fetchedAt:Date.now()};sessionStorage.setItem(ie,JSON.stringify(t));}catch{}}function O(){return !!document.getElementById(re)}function ne(e){if(O()||!e||!Array.isArray(e.traps)||e.traps.length===0)return;let t=document.createElement("div");t.id=re,t.setAttribute("aria-hidden","true"),t.setAttribute("data-serge-traps","1"),t.style.setProperty("position","absolute"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip-path","inset(50%)");for(let r of e.traps){let n=oe(r.root);n&&(n.setAttribute("data-serge-trap-id",String(r.id??"")),n.setAttribute("data-serge-trap-kind",String(r.kind??"")),t.appendChild(n),Ae(n,r));}document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>document.body&&document.body.appendChild(t),{once:true});}function B(e){if(e.enabled===false||O())return;let t=xe();t&&ne(t);let r=`${e.apiBase}/api/v1/trap-config?s=${encodeURIComponent(e.siteId)}&sid=${encodeURIComponent(e.sessionId)}`;fetch(r,{method:"GET",credentials:"omit"}).then(n=>n.ok?n.json():null).then(n=>{!n||!Array.isArray(n.traps)||(ke(n),O()||ne(n));}).catch(()=>{});}var Re=new Set(["access_token","api_key","apikey","auth","authorization","bearer","code","cvc","cvv","email","id_token","jwt","key","oauth_token","one_time_password","otp","password","pin","refresh_token","reset_token","secret","session","sig","signature","ssn","token"]);function se(e){if(!e)return "";if(!e.includes("?"))return e;let t,r=false;try{e.startsWith("/")||!/^[a-z]+:\/\//i.test(e)&&!e.startsWith("//")?(t=new URL(e,"https://placeholder.invalid"),r=!0):t=new URL(e);}catch{return e}if(t.searchParams.size===0)return e;let n=false;for(let i of Array.from(t.searchParams.keys()))Re.has(i.toLowerCase())&&(t.searchParams.delete(i),n=true);return n?r?t.pathname+t.search+t.hash:t.toString():e}var ae="_s_sid",v=null;function Ie(){let e=new Uint8Array(12);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(36).padStart(2,"0")).join("")}function w(){if(v)return v;try{let e=sessionStorage.getItem(ae);if(e)return v=e,e}catch{}v=Ie();try{sessionStorage.setItem(ae,v);}catch{}return v}function N(){let e=Date.now().toString(36),t=new Uint8Array(4);crypto.getRandomValues(t);let r=Array.from(t,n=>n.toString(36).padStart(2,"0")).join("");return `${e}-${r}`}var ce="0.2.2";var A=false,l=null,f=null,E=0,x="",U=0,S=false,p="unknown",y="",V=false;function k(){return l?l.debug?true:!!f&&f.confidence>=.35:false}function R(){return typeof window<"u"&&typeof document<"u"}function ot(e,t={}){if(!R())return;if(!e){t.debug&&console.error("[serge] init(token) requires a token");return}let r=performance.now(),n=(t.apiBase??"https://serge.ai").replace(/\/$/,"");y=n,D(`${n}/api/ingest/snippet`),l={token:e,apiBase:n,debug:t.debug??false,requireConsent:t.requireConsent??false,defaults:t.defaults},A=true,U=performance.now()-r,!(l.requireConsent&&(p=ee(),p==="denied"||p!=="granted"))&&(de(),B({apiBase:n,siteId:e,sessionId:w()}),P(n),document.visibilityState==="hidden"||document.visibilityState==="prerender"?document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&T();},{once:true}):T());}function de(){if(!l)return;let e={s:l.token,sid:w(),eid:N(),ap:"unknown",ac:0,ds:[],et:"init",ts:new Date().toISOString(),u:location.pathname,t:document.title||void 0};m(e);}async function T(){if(!l)return;E=performance.now(),x=location.pathname;let{immediate:e,refine:t}=Y();f=e,(l.debug||e.confidence>=.35)&&(ue(),H(),le());let r=await t;f=r,!l.debug&&e.confidence<.35&&r.confidence>=.35&&(ue(),H(),le());}function le(){V||(V=true,Q(fe),document.addEventListener("visibilitychange",De),window.addEventListener("pagehide",Me));}function C(e,t){if(!l||!f)throw new Error("[serge] tracker not initialized \u2014 call init() first");let r=document.referrer?se(document.referrer):"";return {s:l.token,sid:w(),eid:N(),ap:f.platform,ac:Math.round(f.confidence*100)/100,ds:f.signals,bs:f.behavioralScore!=null?Math.round(f.behavioralScore*100)/100:void 0,et:e,ts:new Date().toISOString(),u:location.pathname,r:r||void 0,t:document.title||void 0,...t}}function ue(){S=false;let e={init_ms:Math.round(U),v:ce,sv:3};l?.defaults&&(e.d=l.defaults),m(C("session_start",{vw:window.innerWidth,vh:window.innerHeight,sw:screen.width,sh:screen.height,ua:navigator.userAgent,p:Pe(),l:navigator.language,_m:e}));}function H(){E=performance.now(),x=location.pathname,m(C("page_view"));}function fe(){if(!k())return;let e=Math.round(performance.now()-E);m(C("route_change",{u:x,tp:e,sd:ge()})),H(),S=false;}function De(){document.visibilityState==="hidden"&&pe();}function Me(){pe();}function pe(){if(S||!k())return;S=true;let e=Math.round(performance.now()-E);F(C("session_end",{tp:e,sd:ge()}));}function ge(){let e=document.documentElement.scrollHeight,t=window.innerHeight;if(e<=t)return 100;let r=window.scrollY||document.documentElement.scrollTop;return Math.min(100,Math.round((r+t)/e*100))}function Pe(){try{return navigator.userAgentData?.platform??navigator.platform??""}catch{return ""}}function st(e,t){!R()||!A||k()&&m(C("semantic_action",{ix:[{t:e,tg:JSON.stringify(t??{}),o:0,ok:true}]}));}function at(e){if(!R())return;let t=p;p=te(e),!(!l||!l.requireConsent)&&t!==p&&p==="granted"&&t!=="granted"&&(y!==""&&P(y),de(),y!==""&&B({apiBase:y,siteId:l.token,sessionId:w()}),document.visibilityState==="hidden"||document.visibilityState==="prerender"?document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&T();},{once:true}):T());}function ct(){!R()||!A||k()&&fe();}function lt(){A=false,l=null,f=null,E=0,x="",U=0,S=false,p="unknown",y="",V=false,D("");}
|
|
2
2
|
export{ce as SDK_VERSION,lt as _resetForTesting,at as consent,ot as init,ct as pageview,st as track};//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/s.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";let e="_s_sid",t=null;function n(){let n;if(t)return t;try{let n=sessionStorage.getItem(e);if(n)return t=n,n}catch{}n=new Uint8Array(12),crypto.getRandomValues(n),t=Array.from(n,e=>e.toString(36).padStart(2,"0")).join("");try{sessionStorage.setItem(e,t)}catch{}return t}function i(){let e=Date.now().toString(36),t=new Uint8Array(4);crypto.getRandomValues(t);let n=Array.from(t,e=>e.toString(36).padStart(2,"0")).join("");return`${e}-${n}`}let r=null,o=!1,a=null;function s(){r&&r.mouseMoveCount++}function c(){r&&(r.anyHoverDetected=!0)}function l(){r&&r.scrollEvents++}function u(){if(!r)return;let e=performance.now();r.clickCount++,r.clickTimestamps.push(e),null===r.firstInteractionMs&&(r.firstInteractionMs=e-r.pageLoadTime)}let d="";function h(e){if(!d)return;let t=JSON.stringify(e);p(t).catch(()=>{setTimeout(()=>p(t).catch(()=>{}),2e3)})}function p(e){return fetch(d,{method:"POST",body:e,headers:{"Content-Type":"text/plain"},keepalive:!0,credentials:"omit"}).then(e=>{if(!e.ok&&429!==e.status)throw Error(`HTTP ${e.status}`)})}let f="",m=null;function g(){let e=location.pathname+location.search;e!==f&&(f=e,m?.())}function y(e){fetch(`${e}/api/v1/signals`,{method:"GET",credentials:"omit"}).then(e=>{if(e.ok)return e.json()}).then(e=>{if(e)try{let t={data:e,fetchedAt:Date.now()};sessionStorage.setItem("serge_signals",JSON.stringify(t))}catch{}}).catch(()=>{})}let v="_serge_consent",w=null;function b(e){if("granted"!==e&&"denied"!==e&&"unknown"!==e)return w??"unknown";w=e;if("unknown"!==e)try{window.localStorage.setItem(v,e)}catch{}return e}let _="serge-traps-root",S="serge_trap_config",k=new Set(["div","span","p","a","button","select","option","h1","h2","h3","h4","h5","h6","ul","li","img","form","input","label"]),E=new Set(["role","aria-label","aria-hidden","aria-describedby","aria-labelledby","tabindex","href","target","rel","type","name","value","placeholder","src","alt","data-trap","data-trap-kind","data-trap-token"]),A=new Set(["position","top","left","right","bottom","width","height","overflow","visibility","opacity","clip-path","clip","pointer-events","color","background","background-color","font-size"]),C=new Set(["click","change","submit","mouseover","focus"]);function x(){return!!document.getElementById(_)}function L(e){if(x()||!e||!Array.isArray(e.traps)||0===e.traps.length)return;let t=document.createElement("div");for(let n of(t.id=_,t.setAttribute("aria-hidden","true"),t.setAttribute("data-serge-traps","1"),t.style.setProperty("position","absolute"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip-path","inset(50%)"),e.traps)){let e=function e(t){let n=String(t.tag??"").toLowerCase();if(!k.has(n))return null;let i=document.createElement(n);if(t.attrs&&"object"==typeof t.attrs){for(let[e,n]of Object.entries(t.attrs))if(E.has(e)&&"string"==typeof n)try{i.setAttribute(e,n)}catch{}}if(t.style&&"object"==typeof t.style){for(let[e,n]of Object.entries(t.style))if(A.has(e)&&"string"==typeof n)try{i.style.setProperty(e,n)}catch{}}if("string"==typeof t.text&&i.appendChild(document.createTextNode(t.text)),Array.isArray(t.children))for(let n of t.children){let t=e(n);t&&i.appendChild(t)}return i}(n.root);e&&(e.setAttribute("data-serge-trap-id",String(n.id??"")),e.setAttribute("data-serge-trap-kind",String(n.kind??"")),t.appendChild(e),function(e,t){for(let n of t.triggers){if(!C.has(n.event))continue;let i=e.querySelector(n.selector);i&&i.addEventListener(n.event,()=>{!function(e){try{if("sendBeacon"in navigator)return void navigator.sendBeacon(e)}catch{}try{fetch(e,{method:"GET",mode:"no-cors",credentials:"omit",keepalive:!0}).catch(()=>void 0)}catch{}}(t.trapUrl)},{once:!0,capture:!0})}}(e,n))}document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>document.body&&document.body.appendChild(t),{once:!0})}function M(e){if(!1===e.enabled||x())return;let t=function(){try{let e=sessionStorage.getItem(S);if(!e)return null;let t=JSON.parse(e);if(Date.now()-t.fetchedAt>36e5)return null;return t.data}catch{return null}}();t&&L(t),fetch(`${e.apiBase}/api/v1/trap-config?s=${encodeURIComponent(e.siteId)}&sid=${encodeURIComponent(e.sessionId)}`,{method:"GET",credentials:"omit"}).then(e=>e.ok?e.json():null).then(e=>{if(e&&Array.isArray(e.traps)){try{let t={data:e,fetchedAt:Date.now()};sessionStorage.setItem(S,JSON.stringify(t))}catch{}x()||L(e)}}).catch(()=>void 0)}let I=new Set(["access_token","api_key","apikey","auth","authorization","bearer","code","cvc","cvv","email","id_token","jwt","key","oauth_token","one_time_password","otp","password","pin","refresh_token","reset_token","secret","session","sig","signature","ssn","token"]),T=null,P=null,D=0,O="",N=0,B=!1,R=!1,j=!1,U="unknown";function H(){return!!R||!!P&&P.confidence>=.35}function W(e){if(!j||!T)return void b(e);let t=U;t===(U=b(e))||"denied"!==U&&"granted"===U&&"granted"!==t&&(""!==G&&y(G),$(T.siteId),""!==G&&M({apiBase:G,siteId:T.siteId,sessionId:n()}),"hidden"===document.visibilityState||"prerender"===document.visibilityState?document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&q()},{once:!0}):q())}let G="";function $(e){h({s:e,sid:n(),eid:i(),ap:"unknown",ac:0,ds:[],et:"init",ts:new Date().toISOString(),u:location.pathname,t:document.title||void 0})}async function q(){if(!T)return;D=performance.now(),O=location.pathname;let{immediate:e,refine:t}=function(){let e=function(){let e=[],t="unknown";try{!0===navigator.webdriver&&e.push("webdriver")}catch{e.push("webdriver_error")}for(let n of(("__playwright__binding__"in window||"__pwInitScripts"in window)&&(e.push("playwright_globals"),t="browser_use"),[{selector:'[id^="claude-agent-"]',signal:"claude_dom",platform:"claude"},{selector:'[id^="comet-agent-"]',signal:"comet_dom",platform:"perplexity"},{selector:'[id^="perplexity-comet-"]',signal:"comet_dom_alt",platform:"perplexity"},{selector:'[id^="chatgpt-atlas-"]',signal:"atlas_dom",platform:"chatgpt"},{selector:'[id^="openai-atlas-"]',signal:"atlas_dom_alt",platform:"chatgpt"}]))document.querySelector(n.selector)&&(e.push(n.signal),t=n.platform);let n=navigator.userAgent;return(/PerplexityBot\/|Perplexity-User\//i.test(n)?(e.push("perplexity_ua"),t="perplexity"):/OAI-SearchBot\//i.test(n)?(e.push("oai_searchbot_ua"),t="chatgpt"):/ChatGPT-User\//i.test(n)?(e.push("chatgpt_user_ua"),t="chatgpt"):/Operator\//i.test(n)?(e.push("operator_ua"),t="chatgpt"):/GPTBot\//i.test(n)?(e.push("gptbot_ua"),t="chatgpt"):/ClaudeBot\//i.test(n)?(e.push("claudebot_ua"),t="claude"):/Claude-User\/|claude-web\//i.test(n)?(e.push("claude_user_ua"),t="claude"):/Claude-SearchBot\//i.test(n)?(e.push("claude_searchbot_ua"),t="claude"):/Claude-Code\//i.test(n)?(e.push("claude_code_ua"),t="claude"):/Google-Extended\//i.test(n)?(e.push("google_extended_ua"),t="gemini"):/Applebot-Extended\//i.test(n)?(e.push("applebot_extended_ua"),t="apple"):/Applebot\//i.test(n)?(e.push("applebot_ua"),t="apple"):/Meta-ExternalAgent\/|Meta-ExternalFetcher\//i.test(n)?(e.push("meta_externalagent_ua"),t="meta"):/bingbot\/|BingPreview\//i.test(n)&&(e.push("bingbot_ua"),t="bing"),0===e.length)?null:{platform:t,confidence:.99,signals:e}}();if(e&&e.confidence>=.85)return{immediate:e,refine:Promise.resolve(e)};let t=function(){let e,t=[],n=0;try{let i=navigator.userAgent,r=/Macintosh|Mac OS X/i.test(i),o=/Windows NT/i.test(i),a=navigator.userAgentData;a&&"Linux"===a.platform&&(r||o)&&(t.push("platform_mismatch"),n+=.5,e="chatgpt")}catch{}try{let i=navigator.userAgent,r=navigator.userAgentData;if(r&&Array.isArray(r.brands)&&/Chrome\//i.test(i)){let i=r.brands.map(e=>e.brand),o=i.some(e=>/Google Chrome/i.test(e)),a=i.some(e=>/Chromium/i.test(e));!o&&a&&(t.push("brand_list_anomaly"),n+=.4,e=e??"chatgpt")}}catch{}try{let e=navigator.userAgent;/Mobile|Android|iPhone/i.test(e)&&0===navigator.maxTouchPoints&&(t.push("touch_mismatch"),n+=.3)}catch{}try{(0===screen.width||0===screen.height)&&(t.push("zero_screen"),n+=.4),0===screen.colorDepth&&(t.push("zero_colordepth"),n+=.3)}catch{}try{window.innerWidth>0&&window.outerWidth>0&&window.outerWidth<window.innerWidth&&(t.push("viewport_mismatch"),n+=.2)}catch{}try{"Notification"in window||(t.push("missing_notification_api"),n+=.2)}catch{}try{let e=document.createElement("canvas"),i=e.getContext("webgl")||e.getContext("experimental-webgl");if(i){let e=i.getExtension("WEBGL_debug_renderer_info"),r=(e?String(i.getParameter(e.UNMASKED_RENDERER_WEBGL)):String(i.getParameter(i.RENDERER))).toLowerCase();(r.includes("swiftshader")||r.includes("swangle")||r.includes("llvmpipe")||r.includes("mesa offscreen"))&&(t.push("webgl_software_renderer"),n+=.45)}else null===i&&(t.push("missing_webgl"),n+=.25)}catch{}try{let e=document.createElement("canvas");e.width=32,e.height=16;let i=e.getContext("2d");if(i){i.textBaseline="top",i.font='13px "Arial"',i.fillStyle="#f60",i.fillRect(0,0,32,16),i.fillStyle="#069",i.fillText("serge:ag",1,1);let e=i.getImageData(0,0,32,16).data,r=0,o=0;for(let t=0;t<e.length;t+=4)0===e[t]&&0===e[t+1]&&0===e[t+2]&&r++,e[t]>o&&(o=e[t]);r/(e.length/4)>.95&&o<20&&(t.push("canvas_flat_render"),n+=.2)}}catch{}try{let e=navigator.userAgentData;if(e&&"function"==typeof e.getHighEntropyValues){let i=navigator.userAgent,r=/Chrome\/(\d+)/i.exec(i);if(r&&Array.isArray(e.brands)){let i=Number(r[1]),o=e.brands.find(e=>/Chrome/i.test(e.brand)&&!/Chromium/i.test(e.brand));if(o&&"string"==typeof o.version){let e=Number(o.version.split(".")[0]);Number.isFinite(i)&&Number.isFinite(e)&&Math.abs(i-e)>2&&(t.push("ua_version_major_mismatch"),n+=.35)}}}}catch{}return{signals:t,score:n=Math.min(n,1),platform:e}}(),n=[...e?.signals??[],...t.signals],i=e?.platform??t.platform??"unknown",d=Math.min((e?.confidence??0)*.5+t.score,1),h={platform:i,confidence:d,signals:[...n]};return d>=.85?{immediate:h,refine:Promise.resolve(h)}:{immediate:h,refine:(function(e=5e3){return o?new Promise(e=>{a=e}):(r={mouseMoveCount:0,scrollEvents:0,clickCount:0,clickTimestamps:[],anyHoverDetected:!1,firstInteractionMs:null,pageLoadTime:performance.now()},o=!0,document.addEventListener("mousemove",s,{passive:!0}),document.addEventListener("mouseover",c,{passive:!0}),document.addEventListener("scroll",l,{passive:!0}),document.addEventListener("click",u,{passive:!0}),new Promise(t=>{a=t,setTimeout(()=>{document.removeEventListener("mousemove",s),document.removeEventListener("mouseover",c),document.removeEventListener("scroll",l),document.removeEventListener("click",u),o=!1;let e=function(){if(!r)return{signals:[],score:0};let e=[],t=0;if(0===r.mouseMoveCount&&r.clickCount>0&&(e.push("no_mouse"),t+=.3),null!==r.firstInteractionMs&&r.firstInteractionMs<100&&(e.push("fast_interaction"),t+=.4),r.clickCount>0&&!r.anyHoverDetected&&0===r.mouseMoveCount&&(e.push("no_hover"),t+=.2),r.clickTimestamps.length>=3){let n=[];for(let e=1;e<r.clickTimestamps.length;e++)n.push(r.clickTimestamps[e]-r.clickTimestamps[e-1]);let i=n.reduce((e,t)=>e+t,0)/n.length,o=n.reduce((e,t)=>e+(t-i)**2,0)/n.length;(i>0?Math.sqrt(o)/i:0)<.1&&(e.push("mechanical_timing"),t+=.3)}return 0===r.scrollEvents&&document.documentElement.scrollHeight>2*window.innerHeight&&r.clickCount>0&&(e.push("no_scroll"),t+=.15),{signals:e,score:Math.min(t,1)}}();r=null,a&&(a(e),a=null)},e)}))})(5e3).then(e=>{let t=[...n,...e.signals],r=e.score;return{platform:i,confidence:d>0?Math.min(.3*d+.7*r,1):.85*r,signals:t,behavioralScore:r}})}}();P=e,(R||e.confidence>=.35)&&(F(),V(),z());let n=await t;P=n,!R&&e.confidence<.35&&n.confidence>=.35&&(F(),V(),z())}function z(){if(m=K,f=location.pathname+location.search,"navigation"in window)window.navigation.addEventListener("navigatesuccess",()=>{g()});else{let e=history.pushState,t=history.replaceState;history.pushState=function(...t){e.apply(this,t),g()},history.replaceState=function(...e){t.apply(this,e),g()},window.addEventListener("popstate",g)}window.addEventListener("pageshow",e=>{e.persisted&&g()}),document.addEventListener("visibilitychange",X),window.addEventListener("pagehide",Y)}function J(e,t){if(!T||!P)throw Error("Not initialized");let r=document.referrer?function(e){let t;if(!e)return"";if(!e.includes("?"))return e;let n=!1;try{!e.startsWith("/")&&(/^[a-z]+:\/\//i.test(e)||e.startsWith("//"))?t=new URL(e):(t=new URL(e,"https://placeholder.invalid"),n=!0)}catch{return e}if(0===t.searchParams.size)return e;let i=!1;for(let e of Array.from(t.searchParams.keys()))I.has(e.toLowerCase())&&(t.searchParams.delete(e),i=!0);return i?n?t.pathname+t.search+t.hash:t.toString():e}(document.referrer):"";return{s:T.siteId,sid:n(),eid:i(),ap:P.platform,ac:Math.round(100*P.confidence)/100,ds:P.signals,bs:null!=P.behavioralScore?Math.round(100*P.behavioralScore)/100:void 0,et:e,ts:new Date().toISOString(),u:location.pathname,r:r||void 0,t:document.title||void 0,...t}}function F(){B=!1,h(J("session_start",{vw:window.innerWidth,vh:window.innerHeight,sw:screen.width,sh:screen.height,ua:navigator.userAgent,p:function(){try{return navigator.userAgentData?.platform??navigator.platform??""}catch{return""}}(),l:navigator.language,_m:{init_ms:Math.round(N),v:"0.2.1",sv:3}}))}function V(){D=performance.now(),O=location.pathname,h(J("page_view"))}function K(){if(!H())return;let e=Math.round(performance.now()-D);h(J("route_change",{u:O,tp:e,sd:Z()})),V(),B=!1}function X(){"hidden"===document.visibilityState&&Q()}function Y(){Q()}function Q(){B||!H()||(B=!0,function(e){if(!d)return;let t=JSON.stringify(e);if("function"==typeof fetchLater)try{fetchLater(d,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},activateAfter:0,credentials:"omit"});return}catch{}try{navigator.sendBeacon(d,t)}catch{fetch(d,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},keepalive:!0,credentials:"omit"}).catch(()=>{})}}(J("session_end",{tp:Math.round(performance.now()-D),sd:Z()})))}function Z(){let e=document.documentElement.scrollHeight,t=window.innerHeight;return e<=t?100:Math.min(100,Math.round(((window.scrollY||document.documentElement.scrollTop)+t)/e*100))}function ee(e,t){H()&&h(J("semantic_action",{ix:[{t:e,tg:JSON.stringify(t??{}),o:0,ok:!0}]}))}function et(e){H()&&h(J("semantic_action",{ix:[{t:"identify",tg:JSON.stringify(e),o:0,ok:!0}]}))}function en(...e){let t=e[0];"track"===t&&"string"==typeof e[1]?ee(e[1],e[2]):"identify"===t&&"object"==typeof e[1]&&null!==e[1]?et(e[1]):"consent"===t&&"string"==typeof e[1]&&W(e[1])}let ei=Object.assign(en,{track:ee,identify:et,consent:e=>W(e)});window.serge=ei;let er=window._sq;if(er){for(let e of er)en(...e);window._sq=void 0}!function(){let e,t=performance.now(),i=document.currentScript??document.querySelector("script[data-site-id]");if(!i)return;let r=i.getAttribute("data-site-id");if(!r)return;let o=i.getAttribute("data-api");if(o)e=o;else if(i.src)try{e=new URL(i.src).origin}catch{e=location.origin}else e=location.origin;let a=`${e}/api/ingest/snippet`;R="true"===i.getAttribute("data-debug"),i.hasAttribute("data-no-cookie")&&console.info("[serge] data-no-cookie is the default since snippet v3 — the attribute can be removed."),j="true"===i.getAttribute("data-require-consent"),T={siteId:r,apiEndpoint:a},G=e,d=a,N=performance.now()-t,j&&("denied"===(U=null!==w?w:w=function(){try{let e=window.localStorage.getItem(v);if("granted"===e||"denied"===e)return e}catch{}return"unknown"}())||"granted"!==U)||($(r),M({apiBase:e,siteId:r,sessionId:n()}),y(e),"hidden"===document.visibilityState||"prerender"===document.visibilityState?document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&q()},{once:!0}):q())}()}();
|
|
1
|
+
!function(){"use strict";let e="_s_sid",t=null;function n(){let n;if(t)return t;try{let n=sessionStorage.getItem(e);if(n)return t=n,n}catch{}n=new Uint8Array(12),crypto.getRandomValues(n),t=Array.from(n,e=>e.toString(36).padStart(2,"0")).join("");try{sessionStorage.setItem(e,t)}catch{}return t}function i(){let e=Date.now().toString(36),t=new Uint8Array(4);crypto.getRandomValues(t);let n=Array.from(t,e=>e.toString(36).padStart(2,"0")).join("");return`${e}-${n}`}let r=null,o=!1,a=null;function s(){r&&r.mouseMoveCount++}function c(){r&&(r.anyHoverDetected=!0)}function l(){r&&r.scrollEvents++}function u(){if(!r)return;let e=performance.now();r.clickCount++,r.clickTimestamps.push(e),null===r.firstInteractionMs&&(r.firstInteractionMs=e-r.pageLoadTime)}let d="";function h(e){if(!d)return;let t=JSON.stringify(e);p(t).catch(()=>{setTimeout(()=>p(t).catch(()=>{}),2e3)})}function p(e){return fetch(d,{method:"POST",body:e,headers:{"Content-Type":"text/plain"},keepalive:!0,credentials:"omit"}).then(e=>{if(!e.ok&&429!==e.status)throw Error(`HTTP ${e.status}`)})}let f="",m=null;function g(){let e=location.pathname+location.search;e!==f&&(f=e,m?.())}function y(e){fetch(`${e}/api/v1/signals`,{method:"GET",credentials:"omit"}).then(e=>{if(e.ok)return e.json()}).then(e=>{if(e)try{let t={data:e,fetchedAt:Date.now()};sessionStorage.setItem("serge_signals",JSON.stringify(t))}catch{}}).catch(()=>{})}let v="_serge_consent",w=null;function b(e){if("granted"!==e&&"denied"!==e&&"unknown"!==e)return w??"unknown";w=e;if("unknown"!==e)try{window.localStorage.setItem(v,e)}catch{}return e}let _="serge-traps-root",S="serge_trap_config",k=new Set(["div","span","p","a","button","select","option","h1","h2","h3","h4","h5","h6","ul","li","img","form","input","label"]),E=new Set(["role","aria-label","aria-hidden","aria-describedby","aria-labelledby","tabindex","href","target","rel","type","name","value","placeholder","src","alt","data-trap","data-trap-kind","data-trap-token"]),A=new Set(["position","top","left","right","bottom","width","height","overflow","visibility","opacity","clip-path","clip","pointer-events","color","background","background-color","font-size"]),C=new Set(["click","change","submit","mouseover","focus"]);function x(){return!!document.getElementById(_)}function L(e){if(x()||!e||!Array.isArray(e.traps)||0===e.traps.length)return;let t=document.createElement("div");for(let n of(t.id=_,t.setAttribute("aria-hidden","true"),t.setAttribute("data-serge-traps","1"),t.style.setProperty("position","absolute"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip-path","inset(50%)"),e.traps)){let e=function e(t){let n=String(t.tag??"").toLowerCase();if(!k.has(n))return null;let i=document.createElement(n);if(t.attrs&&"object"==typeof t.attrs){for(let[e,n]of Object.entries(t.attrs))if(E.has(e)&&"string"==typeof n)try{i.setAttribute(e,n)}catch{}}if(t.style&&"object"==typeof t.style){for(let[e,n]of Object.entries(t.style))if(A.has(e)&&"string"==typeof n)try{i.style.setProperty(e,n)}catch{}}if("string"==typeof t.text&&i.appendChild(document.createTextNode(t.text)),Array.isArray(t.children))for(let n of t.children){let t=e(n);t&&i.appendChild(t)}return i}(n.root);e&&(e.setAttribute("data-serge-trap-id",String(n.id??"")),e.setAttribute("data-serge-trap-kind",String(n.kind??"")),t.appendChild(e),function(e,t){for(let n of t.triggers){if(!C.has(n.event))continue;let i=e.querySelector(n.selector);i&&i.addEventListener(n.event,()=>{!function(e){try{if("sendBeacon"in navigator)return void navigator.sendBeacon(e)}catch{}try{fetch(e,{method:"GET",mode:"no-cors",credentials:"omit",keepalive:!0}).catch(()=>void 0)}catch{}}(t.trapUrl)},{once:!0,capture:!0})}}(e,n))}document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>document.body&&document.body.appendChild(t),{once:!0})}function M(e){if(!1===e.enabled||x())return;let t=function(){try{let e=sessionStorage.getItem(S);if(!e)return null;let t=JSON.parse(e);if(Date.now()-t.fetchedAt>36e5)return null;return t.data}catch{return null}}();t&&L(t),fetch(`${e.apiBase}/api/v1/trap-config?s=${encodeURIComponent(e.siteId)}&sid=${encodeURIComponent(e.sessionId)}`,{method:"GET",credentials:"omit"}).then(e=>e.ok?e.json():null).then(e=>{if(e&&Array.isArray(e.traps)){try{let t={data:e,fetchedAt:Date.now()};sessionStorage.setItem(S,JSON.stringify(t))}catch{}x()||L(e)}}).catch(()=>void 0)}let I=new Set(["access_token","api_key","apikey","auth","authorization","bearer","code","cvc","cvv","email","id_token","jwt","key","oauth_token","one_time_password","otp","password","pin","refresh_token","reset_token","secret","session","sig","signature","ssn","token"]),T=null,P=null,D=0,O="",N=0,B=!1,R=!1,j=!1,U="unknown";function H(){return!!R||!!P&&P.confidence>=.35}function W(e){if(!j||!T)return void b(e);let t=U;t===(U=b(e))||"denied"!==U&&"granted"===U&&"granted"!==t&&(""!==G&&y(G),$(T.siteId),""!==G&&M({apiBase:G,siteId:T.siteId,sessionId:n()}),"hidden"===document.visibilityState||"prerender"===document.visibilityState?document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&q()},{once:!0}):q())}let G="";function $(e){h({s:e,sid:n(),eid:i(),ap:"unknown",ac:0,ds:[],et:"init",ts:new Date().toISOString(),u:location.pathname,t:document.title||void 0})}async function q(){if(!T)return;D=performance.now(),O=location.pathname;let{immediate:e,refine:t}=function(){let e=function(){let e=[],t="unknown";try{!0===navigator.webdriver&&e.push("webdriver")}catch{e.push("webdriver_error")}for(let n of(("__playwright__binding__"in window||"__pwInitScripts"in window)&&(e.push("playwright_globals"),t="browser_use"),[{selector:'[id^="claude-agent-"]',signal:"claude_dom",platform:"claude"},{selector:'[id^="comet-agent-"]',signal:"comet_dom",platform:"perplexity"},{selector:'[id^="perplexity-comet-"]',signal:"comet_dom_alt",platform:"perplexity"},{selector:'[id^="chatgpt-atlas-"]',signal:"atlas_dom",platform:"chatgpt"},{selector:'[id^="openai-atlas-"]',signal:"atlas_dom_alt",platform:"chatgpt"}]))document.querySelector(n.selector)&&(e.push(n.signal),t=n.platform);let n=navigator.userAgent;return(/PerplexityBot\/|Perplexity-User\//i.test(n)?(e.push("perplexity_ua"),t="perplexity"):/OAI-SearchBot\//i.test(n)?(e.push("oai_searchbot_ua"),t="chatgpt"):/ChatGPT-User\//i.test(n)?(e.push("chatgpt_user_ua"),t="chatgpt"):/Operator\//i.test(n)?(e.push("operator_ua"),t="chatgpt"):/GPTBot\//i.test(n)?(e.push("gptbot_ua"),t="chatgpt"):/ClaudeBot\//i.test(n)?(e.push("claudebot_ua"),t="claude"):/Claude-User\/|claude-web\//i.test(n)?(e.push("claude_user_ua"),t="claude"):/Claude-SearchBot\//i.test(n)?(e.push("claude_searchbot_ua"),t="claude"):/Claude-Code\//i.test(n)?(e.push("claude_code_ua"),t="claude"):/Google-Extended\//i.test(n)?(e.push("google_extended_ua"),t="gemini"):/Applebot-Extended\//i.test(n)?(e.push("applebot_extended_ua"),t="apple"):/Applebot\//i.test(n)?(e.push("applebot_ua"),t="apple"):/Meta-ExternalAgent\/|Meta-ExternalFetcher\//i.test(n)?(e.push("meta_externalagent_ua"),t="meta"):/bingbot\/|BingPreview\//i.test(n)&&(e.push("bingbot_ua"),t="bing"),0===e.length)?null:{platform:t,confidence:.99,signals:e}}();if(e&&e.confidence>=.85)return{immediate:e,refine:Promise.resolve(e)};let t=function(){let e,t=[],n=0;try{let i=navigator.userAgent,r=/Macintosh|Mac OS X/i.test(i),o=/Windows NT/i.test(i),a=navigator.userAgentData;a&&"Linux"===a.platform&&(r||o)&&(t.push("platform_mismatch"),n+=.5,e="chatgpt")}catch{}try{let i=navigator.userAgent,r=navigator.userAgentData;if(r&&Array.isArray(r.brands)&&/Chrome\//i.test(i)){let i=r.brands.map(e=>e.brand),o=i.some(e=>/Google Chrome/i.test(e)),a=i.some(e=>/Chromium/i.test(e));!o&&a&&(t.push("brand_list_anomaly"),n+=.4,e=e??"chatgpt")}}catch{}try{let e=navigator.userAgent;/Mobile|Android|iPhone/i.test(e)&&0===navigator.maxTouchPoints&&(t.push("touch_mismatch"),n+=.3)}catch{}try{(0===screen.width||0===screen.height)&&(t.push("zero_screen"),n+=.4),0===screen.colorDepth&&(t.push("zero_colordepth"),n+=.3)}catch{}try{window.innerWidth>0&&window.outerWidth>0&&window.outerWidth<window.innerWidth&&(t.push("viewport_mismatch"),n+=.2)}catch{}try{"Notification"in window||(t.push("missing_notification_api"),n+=.2)}catch{}try{let e=document.createElement("canvas"),i=e.getContext("webgl")||e.getContext("experimental-webgl");if(i){let e=i.getExtension("WEBGL_debug_renderer_info"),r=(e?String(i.getParameter(e.UNMASKED_RENDERER_WEBGL)):String(i.getParameter(i.RENDERER))).toLowerCase();(r.includes("swiftshader")||r.includes("swangle")||r.includes("llvmpipe")||r.includes("mesa offscreen"))&&(t.push("webgl_software_renderer"),n+=.45)}else null===i&&(t.push("missing_webgl"),n+=.25)}catch{}try{let e=document.createElement("canvas");e.width=32,e.height=16;let i=e.getContext("2d");if(i){i.textBaseline="top",i.font='13px "Arial"',i.fillStyle="#f60",i.fillRect(0,0,32,16),i.fillStyle="#069",i.fillText("serge:ag",1,1);let e=i.getImageData(0,0,32,16).data,r=0,o=0;for(let t=0;t<e.length;t+=4)0===e[t]&&0===e[t+1]&&0===e[t+2]&&r++,e[t]>o&&(o=e[t]);r/(e.length/4)>.95&&o<20&&(t.push("canvas_flat_render"),n+=.2)}}catch{}try{let e=navigator.userAgentData;if(e&&"function"==typeof e.getHighEntropyValues){let i=navigator.userAgent,r=/Chrome\/(\d+)/i.exec(i);if(r&&Array.isArray(e.brands)){let i=Number(r[1]),o=e.brands.find(e=>/Chrome/i.test(e.brand)&&!/Chromium/i.test(e.brand));if(o&&"string"==typeof o.version){let e=Number(o.version.split(".")[0]);Number.isFinite(i)&&Number.isFinite(e)&&Math.abs(i-e)>2&&(t.push("ua_version_major_mismatch"),n+=.35)}}}}catch{}return{signals:t,score:n=Math.min(n,1),platform:e}}(),n=[...e?.signals??[],...t.signals],i=e?.platform??t.platform??"unknown",d=Math.min((e?.confidence??0)*.5+t.score,1),h={platform:i,confidence:d,signals:[...n]};return d>=.85?{immediate:h,refine:Promise.resolve(h)}:{immediate:h,refine:(function(e=5e3){return o?new Promise(e=>{a=e}):(r={mouseMoveCount:0,scrollEvents:0,clickCount:0,clickTimestamps:[],anyHoverDetected:!1,firstInteractionMs:null,pageLoadTime:performance.now()},o=!0,document.addEventListener("mousemove",s,{passive:!0}),document.addEventListener("mouseover",c,{passive:!0}),document.addEventListener("scroll",l,{passive:!0}),document.addEventListener("click",u,{passive:!0}),new Promise(t=>{a=t,setTimeout(()=>{document.removeEventListener("mousemove",s),document.removeEventListener("mouseover",c),document.removeEventListener("scroll",l),document.removeEventListener("click",u),o=!1;let e=function(){if(!r)return{signals:[],score:0};let e=[],t=0;if(0===r.mouseMoveCount&&r.clickCount>0&&(e.push("no_mouse"),t+=.3),null!==r.firstInteractionMs&&r.firstInteractionMs<100&&(e.push("fast_interaction"),t+=.4),r.clickCount>0&&!r.anyHoverDetected&&0===r.mouseMoveCount&&(e.push("no_hover"),t+=.2),r.clickTimestamps.length>=3){let n=[];for(let e=1;e<r.clickTimestamps.length;e++)n.push(r.clickTimestamps[e]-r.clickTimestamps[e-1]);let i=n.reduce((e,t)=>e+t,0)/n.length,o=n.reduce((e,t)=>e+(t-i)**2,0)/n.length;(i>0?Math.sqrt(o)/i:0)<.1&&(e.push("mechanical_timing"),t+=.3)}return 0===r.scrollEvents&&document.documentElement.scrollHeight>2*window.innerHeight&&r.clickCount>0&&(e.push("no_scroll"),t+=.15),{signals:e,score:Math.min(t,1)}}();r=null,a&&(a(e),a=null)},e)}))})(5e3).then(e=>{let t=[...n,...e.signals],r=e.score;return{platform:i,confidence:d>0?Math.min(.3*d+.7*r,1):.85*r,signals:t,behavioralScore:r}})}}();P=e,(R||e.confidence>=.35)&&(F(),V(),z());let n=await t;P=n,!R&&e.confidence<.35&&n.confidence>=.35&&(F(),V(),z())}function z(){if(m=K,f=location.pathname+location.search,"navigation"in window)window.navigation.addEventListener("navigatesuccess",()=>{g()});else{let e=history.pushState,t=history.replaceState;history.pushState=function(...t){e.apply(this,t),g()},history.replaceState=function(...e){t.apply(this,e),g()},window.addEventListener("popstate",g)}window.addEventListener("pageshow",e=>{e.persisted&&g()}),document.addEventListener("visibilitychange",X),window.addEventListener("pagehide",Y)}function J(e,t){if(!T||!P)throw Error("Not initialized");let r=document.referrer?function(e){let t;if(!e)return"";if(!e.includes("?"))return e;let n=!1;try{!e.startsWith("/")&&(/^[a-z]+:\/\//i.test(e)||e.startsWith("//"))?t=new URL(e):(t=new URL(e,"https://placeholder.invalid"),n=!0)}catch{return e}if(0===t.searchParams.size)return e;let i=!1;for(let e of Array.from(t.searchParams.keys()))I.has(e.toLowerCase())&&(t.searchParams.delete(e),i=!0);return i?n?t.pathname+t.search+t.hash:t.toString():e}(document.referrer):"";return{s:T.siteId,sid:n(),eid:i(),ap:P.platform,ac:Math.round(100*P.confidence)/100,ds:P.signals,bs:null!=P.behavioralScore?Math.round(100*P.behavioralScore)/100:void 0,et:e,ts:new Date().toISOString(),u:location.pathname,r:r||void 0,t:document.title||void 0,...t}}function F(){B=!1,h(J("session_start",{vw:window.innerWidth,vh:window.innerHeight,sw:screen.width,sh:screen.height,ua:navigator.userAgent,p:function(){try{return navigator.userAgentData?.platform??navigator.platform??""}catch{return""}}(),l:navigator.language,_m:{init_ms:Math.round(N),v:"0.2.2",sv:3}}))}function V(){D=performance.now(),O=location.pathname,h(J("page_view"))}function K(){if(!H())return;let e=Math.round(performance.now()-D);h(J("route_change",{u:O,tp:e,sd:Z()})),V(),B=!1}function X(){"hidden"===document.visibilityState&&Q()}function Y(){Q()}function Q(){B||!H()||(B=!0,function(e){if(!d)return;let t=JSON.stringify(e);if("function"==typeof fetchLater)try{fetchLater(d,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},activateAfter:0,credentials:"omit"});return}catch{}try{navigator.sendBeacon(d,t)}catch{fetch(d,{method:"POST",body:t,headers:{"Content-Type":"text/plain"},keepalive:!0,credentials:"omit"}).catch(()=>{})}}(J("session_end",{tp:Math.round(performance.now()-D),sd:Z()})))}function Z(){let e=document.documentElement.scrollHeight,t=window.innerHeight;return e<=t?100:Math.min(100,Math.round(((window.scrollY||document.documentElement.scrollTop)+t)/e*100))}function ee(e,t){H()&&h(J("semantic_action",{ix:[{t:e,tg:JSON.stringify(t??{}),o:0,ok:!0}]}))}function et(e){H()&&h(J("semantic_action",{ix:[{t:"identify",tg:JSON.stringify(e),o:0,ok:!0}]}))}function en(...e){let t=e[0];"track"===t&&"string"==typeof e[1]?ee(e[1],e[2]):"identify"===t&&"object"==typeof e[1]&&null!==e[1]?et(e[1]):"consent"===t&&"string"==typeof e[1]&&W(e[1])}let ei=Object.assign(en,{track:ee,identify:et,consent:e=>W(e)});window.serge=ei;let er=window._sq;if(er){for(let e of er)en(...e);window._sq=void 0}!function(){let e,t=performance.now(),i=document.currentScript??document.querySelector("script[data-site-id]");if(!i)return;let r=i.getAttribute("data-site-id");if(!r)return;let o=i.getAttribute("data-api");if(o)e=o;else if(i.src)try{e=new URL(i.src).origin}catch{e=location.origin}else e=location.origin;let a=`${e}/api/ingest/snippet`;R="true"===i.getAttribute("data-debug"),i.hasAttribute("data-no-cookie")&&console.info("[serge] data-no-cookie is the default since snippet v3 — the attribute can be removed."),j="true"===i.getAttribute("data-require-consent"),T={siteId:r,apiEndpoint:a},G=e,d=a,N=performance.now()-t,j&&("denied"===(U=null!==w?w:w=function(){try{let e=window.localStorage.getItem(v);if("granted"===e||"denied"===e)return e}catch{}return"unknown"}())||"granted"!==U)||($(r),M({apiBase:e,siteId:r,sessionId:n()}),y(e),"hidden"===document.visibilityState||"prerender"===document.visibilityState?document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&q()},{once:!0}):q())}()}();
|
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serge-ai/js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Serge — agent-traffic tracker for the browser. Detect AI-agent sessions on your site, plus a custom-event API. Cookieless. SSR-safe. MIT-licensed.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://serge.ai",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/SuperstellarLLC/heyserge.git",
|
|
10
|
-
"directory": "packages/js"
|
|
11
|
-
},
|
|
12
7
|
"bugs": {
|
|
13
|
-
"url": "https://
|
|
8
|
+
"url": "https://serge.ai/contact",
|
|
9
|
+
"email": "support@serge.ai"
|
|
14
10
|
},
|
|
15
11
|
"keywords": [
|
|
16
12
|
"analytics",
|