Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main] create snippet mini loader #2339

Merged
merged 30 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b0aeb8d
Create miniLoader.ts
siyuniu-ms May 1, 2024
678dc85
add gruntfile
siyuniu-ms May 2, 2024
26584df
Merge branch 'main' into siyu/miniLoader
siyuniu-ms May 2, 2024
51ac9e8
Update miniLoader.ts
siyuniu-ms May 2, 2024
1ec7b39
Merge branch 'siyu/miniLoader' of https://github.com/microsoft/Applic…
siyuniu-ms May 2, 2024
db05c84
change the way of fetching
siyuniu-ms May 8, 2024
46a67ae
add type
siyuniu-ms May 9, 2024
e4450a5
Update miniLoader.ts
siyuniu-ms May 9, 2024
ba4731d
Merge branch 'main' into siyu/miniLoader
siyuniu-ms May 9, 2024
b9b9ba2
add integrity check
siyuniu-ms May 9, 2024
080b67b
Merge branch 'main' into siyu/miniLoader
siyuniu-ms May 9, 2024
48a89b4
change ver name to integrityUrl
siyuniu-ms Jun 4, 2024
a5ee4ec
rename
siyuniu-ms Jun 7, 2024
0b4a3dd
rename
siyuniu-ms Jun 7, 2024
33e230c
merge into current snippet
siyuniu-ms Jun 11, 2024
8d7f6a6
fix regex
siyuniu-ms Jun 12, 2024
b691c7b
remove unnecessary log
siyuniu-ms Jun 12, 2024
e042ae4
Update snippet.ts
siyuniu-ms Jun 12, 2024
fc16f82
rename and remove version
siyuniu-ms Jun 13, 2024
4c59a36
Merge branch 'main' into siyu/miniLoader
siyuniu-ms Jun 13, 2024
23e26f1
Update testVersionConflict.html
siyuniu-ms Jun 13, 2024
35236fb
Merge branch 'siyu/miniLoader' of https://github.com/microsoft/Applic…
siyuniu-ms Jun 13, 2024
2a938f0
Update snippet.ts
siyuniu-ms Jun 14, 2024
d671d8e
Update snippet.ts
siyuniu-ms Jun 14, 2024
556d1e9
add more error case handler
siyuniu-ms Jun 14, 2024
81e342d
refactor
siyuniu-ms Jun 14, 2024
ca67086
shorten regex
siyuniu-ms Jun 15, 2024
81d125b
update corresponding readme, test and sv version
siyuniu-ms Jun 15, 2024
ee9099d
Update testVersionConflict.html
siyuniu-ms Jun 17, 2024
58e2e8a
Update SnippetTests.ts
siyuniu-ms Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions AISKU/Tests/Manual/testVersionConflict.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
<!DOCTYPE html>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self' https://dc.services.visualstudio.com; script-src 'nonce-EDNnf03nceIOfn39fn3e9h3sdfa' https://js.monitor.azure.com ; img-src https://*; child-src 'none';" />

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<html lang="en">
<head>
<meta charset="utf-8">
<title>AISKU Sample</title>
<link rel="stylesheet" href="style/style.css"/>
<!-- <script src="./ai3.test.js"></script> -->
<!-- <script src="./ai2.test.js"></script> -->
<!-- <script src="./ai3.test.js"></script> -->
<script type="text/javascript" nonce = "EDNnf03nceIOfn39fn3e9h3sdfa">
!(function (cfg){function e(){cfg.onInit&&cfg.onInit(i)}var S,u,D,t,n,i,C=window,x=document,w=C.location,I="script",b="ingestionendpoint",E="disableExceptionTracking",A="ai.device.";"instrumentationKey"[S="toLowerCase"](),u="crossOrigin",D="POST",t="appInsightsSDK",n=cfg.name||"appInsights",(cfg.name||C[t])&&(C[t]=n),i=C[n]||function(l){var d=!1,g=!1,f={initialize:!0,queue:[],sv:"7",version:2,config:l};function m(e,t){var n={},i="Browser";function a(e){e=""+e;return 1===e.length?"0"+e:e}return n[A+"id"]=i[S](),n[A+"type"]=i,n["ai.operation.name"]=w&&w.pathname||"_unknown_",n["ai.internal.sdkVersion"]="javascript:snippet_"+(f.sv||f.version),{time:(i=new Date).getUTCFullYear()+"-"+a(1+i.getUTCMonth())+"-"+a(i.getUTCDate())+"T"+a(i.getUTCHours())+":"+a(i.getUTCMinutes())+":"+a(i.getUTCSeconds())+"."+(i.getUTCMilliseconds()/1e3).toFixed(3).slice(2,5)+"Z",iKey:e,name:"Microsoft.ApplicationInsights."+e.replace(/-/g,"")+"."+t,sampleRate:100,tags:n,data:{baseData:{ver:2}},ver:4,seq:"1",aiDataContract:undefined}}var h=-1,v=0,y=["js.monitor.azure.com","js.cdn.applicationinsights.io","js.cdn.monitor.azure.com","js0.cdn.applicationinsights.io","js0.cdn.monitor.azure.com","js2.cdn.applicationinsights.io","js2.cdn.monitor.azure.com","az416426.vo.msecnd.net"],k=l.url||cfg.src;if(k){if((n=navigator)&&(~(n=(n.userAgent||"").toLowerCase()).indexOf("msie")||~n.indexOf("trident/"))&&~k.indexOf("ai.3")&&(k=k.replace(/(\/)(ai\.3\.)([^\d]*)$/,function(e,t,n){return t+"ai.2"+n})),!1!==cfg.cr)for(var e=0;e<y.length;e++)if(0<k.indexOf(y[e])){h=e;break}var i=function(e){var a,t,n,i,o,r,s,c,p,u;f.queue=[],g||(0<=h&&v+1<y.length?(a=(h+v+1)%y.length,T(k.replace(/^(.*\/\/)([\w\.]*)(\/.*)$/,function(e,t,n,i){return t+y[a]+i})),v+=1):(d=g=!0,o=k,c=(p=function(){var e,t={},n=l.connectionString;if(n)for(var i=n.split(";"),a=0;a<i.length;a++){var o=i[a].split("=");2===o.length&&(t[o[0][S]()]=o[1])}return t[b]||(e=(n=t.endpointsuffix)?t.location:null,t[b]="https://"+(e?e+".":"")+"dc."+(n||"services.visualstudio.com")),t}()).instrumentationkey||l.instrumentationKey||"",p=(p=p[b])?p+"/v2/track":l.endpointUrl,(u=[]).push((t="SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details)",n=o,r=p,(s=(i=m(c,"Exception")).data).baseType="ExceptionData",s.baseData.exceptions=[{typeName:"SDKLoadFailed",message:t.replace(/\./g,"-"),hasFullStack:!1,stack:t+"\nSnippet failed to load ["+n+"] -- Telemetry is disabled\nHelp Link: https://go.microsoft.com/fwlink/?linkid=2128109\nHost: "+(w&&w.pathname||"_unknown_")+"\nEndpoint: "+r,parsedStack:[]}],i)),u.push((s=o,t=p,(r=(n=m(c,"Message")).data).baseType="MessageData",(i=r.baseData).message='AI (Internal): 99 message:"'+("SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details) ("+s+")").replace(/\"/g,"")+'"',i.properties={endpoint:t},n)),o=u,c=p,JSON&&((r=C.fetch)&&!cfg.useXhr?r(c,{method:D,body:JSON.stringify(o),mode:"cors"}):XMLHttpRequest&&((s=new XMLHttpRequest).open(D,c),s.setRequestHeader("Content-type","application/json"),s.send(JSON.stringify(o))))))},a=function(e,t){g||setTimeout(function(){!t&&f.core||i()},500),d=!1},T=function(e){var n=x.createElement(I),e=(n.src=e,cfg[u]);return!e&&""!==e||"undefined"==n[u]||(n[u]=e),n.onload=a,n.onerror=i,n.onreadystatechange=function(e,t){"loaded"!==n.readyState&&"complete"!==n.readyState||a(0,t)},cfg.ld&&cfg.ld<0?x.getElementsByTagName("head")[0].appendChild(n):setTimeout(function(){x.getElementsByTagName(I)[0].parentNode.appendChild(n)},cfg.ld||0),n};T(k)}try{f.cookie=x.cookie}catch(p){}function t(e){for(;e.length;)!function(t){f[t]=function(){var e=arguments;d||f.queue.push(function(){f[t].apply(f,e)})}}(e.pop())}var r,s,n="track",o="TrackPage",c="TrackEvent",n=(t([n+"Event",n+"PageView",n+"Exception",n+"Trace",n+"DependencyData",n+"Metric",n+"PageViewPerformance","start"+o,"stop"+o,"start"+c,"stop"+c,"addTelemetryInitializer","setAuthenticatedUserContext","clearAuthenticatedUserContext","flush"]),f.SeverityLevel={Verbose:0,Information:1,Warning:2,Error:3,Critical:4},(l.extensionConfig||{}).ApplicationInsightsAnalytics||{});return!0!==l[E]&&!0!==n[E]&&(t(["_"+(r="onerror")]),s=C[r],C[r]=function(e,t,n,i,a){var o=s&&s(e,t,n,i,a);return!0!==o&&f["_"+r]({message:e,url:t,lineNumber:n,columnNumber:i,error:a,evt:C.event}),o},l.autoExceptionInstrumented=!0),f}(cfg.cfg),(C[n]=i).queue&&0===i.queue.length?(i.queue.push(e),i.trackPageView({})):e();})({
src: "https://js.monitor.azure.com/scripts/b/ai.3.gbl.min.js",
// name: "appInsights", // Global SDK Instance name defaults to "appInsights" when not supplied
// ld: 0, // Defines the load delay (in ms) before attempting to load the sdk. -1 = block page load and add to head. (default) = 0ms load after timeout,
// useXhr: 1, // Use XHR instead of fetch to report failures (if available),
// dle: true, // Prevent the SDK from reporting load failure log
crossOrigin: "anonymous", // When supplied this will add the provided value as the cross origin attribute on the script tag
// onInit: null, // Once the application insights instance has loaded and initialized this callback function will be called with 1 argument -- the sdk instance (DO NOT ADD anything to the sdk.queue -- As they won't get called)
cfg: { // Application Insights Configuration
connectionString: "InstrumentationKey=88888888"
}
});

<script src="https://requirejs.org/docs/release/2.3.6/minified/require.js" type="text/javascript"></script>
<script type="text/javascript">
!(function (cfg){function e(){cfg.onInit&&cfg.onInit(i)}var k,x,D,t,n,i,E=window,w=document,C=E.location,O="script",b="ingestionendpoint",q="disableExceptionTracking",I="ai.device.";"instrumentationKey"[k="toLowerCase"](),x="crossOrigin",D="POST",t="appInsightsSDK",n=cfg.name||"appInsights",(cfg.name||E[t])&&(E[t]=n),i=E[n]||function(g){var f=!1,m=!1,h={initialize:!0,queue:[],sv:"7",version:2,config:g};function v(e,t){var n={},i="Browser";function a(e){e=""+e;return 1===e.length?"0"+e:e}return n[I+"id"]=i[k](),n[I+"type"]=i,n["ai.operation.name"]=C&&C.pathname||"_unknown_",n["ai.internal.sdkVersion"]="javascript:snippet_"+(h.sv||h.version),{time:(i=new Date).getUTCFullYear()+"-"+a(1+i.getUTCMonth())+"-"+a(i.getUTCDate())+"T"+a(i.getUTCHours())+":"+a(i.getUTCMinutes())+":"+a(i.getUTCSeconds())+"."+(i.getUTCMilliseconds()/1e3).toFixed(3).slice(2,5)+"Z",iKey:e,name:"Microsoft.ApplicationInsights."+e.replace(/-/g,"")+"."+t,sampleRate:100,tags:n,data:{baseData:{ver:2}},ver:undefined,seq:"1",aiDataContract:undefined}}var t,n,i,a,y=-1,T=0,S=["js.monitor.azure.com","js.cdn.applicationinsights.io","js.cdn.monitor.azure.com","js0.cdn.applicationinsights.io","js0.cdn.monitor.azure.com","js2.cdn.applicationinsights.io","js2.cdn.monitor.azure.com","az416426.vo.msecnd.net"],o=g.url||cfg.src,e=o.match(/^(https?:\/\/[^/]+)\/.*?\/ai\.(\d+(\.\d+){0,2})\.(.*?)$/);function r(l,t){if((n=navigator)&&(~(n=(n.userAgent||"").toLowerCase()).indexOf("msie")||~n.indexOf("trident/"))&&~l.indexOf("ai.3")&&(l=l.replace(/(\/)(ai\.3\.)([^\d]*)$/,function(e,t,n){return t+"ai.2"+n})),!1!==cfg.cr)for(var e=0;e<S.length;e++)if(0<l.indexOf(S[e])){y=e;break}var n,i=function(e){var a,t,n,i,o,r,s,c,u,d;h.queue=[],m||(0<=y&&T+1<S.length?(a=(y+T+1)%S.length,p(l.replace(/^(.*\/\/)([\w\.]*)(\/.*)$/,function(e,t,n,i){return t+S[a]+i})),T+=1):(f=m=!0,s=l,!0!==cfg.dle&&(c=(t=function(){var e,t={},n=g.connectionString;if(n)for(var i=n.split(";"),a=0;a<i.length;a++){var o=i[a].split("=");2===o.length&&(t[o[0][k]()]=o[1])}return t[b]||(e=(n=t.endpointsuffix)?t.location:null,t[b]="https://"+(e?e+".":"")+"dc."+(n||"services.visualstudio.com")),t}()).instrumentationkey||g.instrumentationKey||"",t=(t=(t=t[b])&&"/"===t.slice(-1)?t.slice(0,-1):t)?t+"/v2/track":g.endpointUrl,t=g.userOverrideEndpointUrl||t,(n=[]).push((i="SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details)",o=s,u=t,(d=(r=v(c,"Exception")).data).baseType="ExceptionData",d.baseData.exceptions=[{typeName:"SDKLoadFailed",message:i.replace(/\./g,"-"),hasFullStack:!1,stack:i+"\nSnippet failed to load ["+o+"] -- Telemetry is disabled\nHelp Link: https://go.microsoft.com/fwlink/?linkid=2128109\nHost: "+(C&&C.pathname||"_unknown_")+"\nEndpoint: "+u,parsedStack:[]}],r)),n.push((d=s,i=t,(u=(o=v(c,"Message")).data).baseType="MessageData",(r=u.baseData).message='AI (Internal): 99 message:"'+("SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details) ("+d+")").replace(/\"/g,"")+'"',r.properties={endpoint:i},o)),s=n,c=t,JSON&&((u=E.fetch)&&!cfg.useXhr?u(c,{method:D,body:JSON.stringify(s),mode:"cors"}):XMLHttpRequest&&((d=new XMLHttpRequest).open(D,c),d.setRequestHeader("Content-type","application/json"),d.send(JSON.stringify(s)))))))},a=function(e,t){m||setTimeout(function(){!t&&h.core||i()},500),f=!1},p=function(e){var n=w.createElement(O),e=(n.src=e,t&&(n.integrity=t),cfg[x]);return!e&&""!==e||"undefined"==n[x]||(n[x]=e),n.onload=a,n.onerror=i,n.onreadystatechange=function(e,t){"loaded"!==n.readyState&&"complete"!==n.readyState||a(0,t)},cfg.ld&&cfg.ld<0?w.getElementsByTagName("head")[0].appendChild(n):setTimeout(function(){w.getElementsByTagName(O)[0].parentNode.appendChild(n)},cfg.ld||0),n};p(l)}5===e.length&&cfg.sri?(d=e[1]+"/beta/ai."+e[2]+".integrity.json",t="@"+e[4],e=window.fetch,n=null,i="3",e&&!cfg.useXhr?e(d,{method:"GET",mode:"cors"}).then(function(e){return e.json()}).then(function(e){i=e.version,n=e.ext[t].integrity,r(o=o.replace(/(?<=\/ai\.)\d+(\.\d+){0,2}/,i),n)})["catch"](function(e){console.error("Error loading JSON:",e),r(o,n)}):XMLHttpRequest&&((a=new XMLHttpRequest).open("GET",d),a.onreadystatechange=function(){var e;a.readyState===XMLHttpRequest.DONE&&(200===a.status?(e=JSON.parse(a.responseText),i=e.version,n=e.ext[t].integrity,r(o=o.replace(/(?<=\/ai\.)\d+(\.\d+){0,2}/,i),n)):(console.error("Error loading JSON:",a.statusText),r(o,n)))},a.send())):o&&r(o,n);try{h.cookie=w.cookie}catch(p){}function s(e){for(;e.length;)!function(t){h[t]=function(){var e=arguments;f||h.queue.push(function(){h[t].apply(h,e)})}}(e.pop())}var c,u,e="track",d="TrackPage",l="TrackEvent",e=(s([e+"Event",e+"PageView",e+"Exception",e+"Trace",e+"DependencyData",e+"Metric",e+"PageViewPerformance","start"+d,"stop"+d,"start"+l,"stop"+l,"addTelemetryInitializer","setAuthenticatedUserContext","clearAuthenticatedUserContext","flush"]),h.SeverityLevel={Verbose:0,Information:1,Warning:2,Error:3,Critical:4},(g.extensionConfig||{}).ApplicationInsightsAnalytics||{});return!0!==g[q]&&!0!==e[q]&&(s(["_"+(c="onerror")]),u=E[c],E[c]=function(e,t,n,i,a){var o=u&&u(e,t,n,i,a);return!0!==o&&h["_"+c]({message:e,url:t,lineNumber:n,columnNumber:i,error:a,evt:E.event}),o},g.autoExceptionInstrumented=!0),h}(cfg.cfg),(E[n]=i).queue&&0===i.queue.length?(i.queue.push(e),i.trackPageView({})):e();})({
src: "https://js.monitor.azure.com/scripts/b/ai.3.gbl.min.js",
// name: "appInsights", // Global SDK Instance name defaults to "appInsights" when not supplied
// ld: 0, // Defines the load delay (in ms) before attempting to load the sdk. -1 = block page load and add to head. (default) = 0ms load after timeout,
// useXhr: 1, // Use XHR instead of fetch to report failures (if available),
// dle: true, // Prevent the SDK from reporting load failure log
crossOrigin: "anonymous", // When supplied this will add the provided value as the cross origin attribute on the script tag
// onInit: null, // Once the application insights instance has loaded and initialized this callback function will be called with 1 argument -- the sdk instance (DO NOT ADD anything to the sdk.queue -- As they won't get called)
sri: true, // Custom optional value to specify whether fetching the snippet from integrity file and do integrity check
cfg: { // Application Insights Configuration
connectionString: "Your-connection-string-here"
}
});
</script>
</head>
<body>
<h1>Microsoft Application Insights JavaScript SDK - AISKU</h1>
<script>
let appInsights = new Microsoft.ApplicationInsights.ApplicationInsights({ config: {connectionString: "InstrumentationKey=88888888", disableInstrumentationKeyValidation: true}});
let appInsights = new ApplicationInsights.ApplicationInsights({ config: {connectionString: "InstrumentationKey=88888888", disableInstrumentationKeyValidation: true}});
appInsights.loadAppInsights();
window.appInsights = appInsights;
</script>
Expand Down
Loading
Loading