Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Nov 7, 2024
1 parent 068ec3a commit cc44c88
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
53 changes: 29 additions & 24 deletions tools/canyon-extension/public/interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,33 @@ window.addEventListener('message', function (e) {
}
});

if (!isNaN(Number(localStorage.getItem('__canyon__interval__time__')))) {
const num = Number(localStorage.getItem('__canyon__interval__time__'));
if (num > 0) {
setInterval(() => {
if (window.__canyon__ && window.__coverage__) {
fetch(window.__canyon__.dsn, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${window.__canyon__.reporter}`,
},
body: JSON.stringify({
coverage: window.__coverage__,
...window.__canyon__,
reportID: localStorage.getItem('__canyon__report__id__') || undefined,
}),
}).then(() => {
console.log('report coverage success');
});
} else {
console.log('coverage or canyon data is not ready');
}
}, num * 1000);
// 1s后再去获取尝试间隔上报
setTimeout(()=>{
// 先尝试本地获取,如果没有再去获取window上的数据
const __canyon__interval__time__ = Number(localStorage.getItem('__canyon__interval__time__')) || Number(window?.__canyon__?.intervalTime);
if (!isNaN(__canyon__interval__time__)) {
const num = __canyon__interval__time__;
if (num > 0) {
setInterval(() => {
if (window.__canyon__ && window.__coverage__) {
fetch(window.__canyon__.dsn, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${window.__canyon__.reporter}`,
},
body: JSON.stringify({
coverage: window.__coverage__,
...window.__canyon__,
reportID: localStorage.getItem('__canyon__report__id__') || undefined,
}),
}).then(() => {
console.log('report coverage success');
});
} else {
console.log('coverage or canyon data is not ready');
}
}, num * 1000);
}
}
}
},1000)
2 changes: 1 addition & 1 deletion tools/canyon-extension/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Canyon Extension",
"version": "1.0.8",
"version": "1.0.9",
"manifest_version": 3,
"description": "Canyon manual report plugin",
"icons": {
Expand Down

0 comments on commit cc44c88

Please sign in to comment.