如今Web庞大复杂应用场景广泛,再加上各种浏览器造成的环境差异,很难保证我们的页面呈现给每个用户时都是正常的。稳定和准确是每个产品的基础,对于用户直接交互的页面更加显得重要。我们不能等到用户投诉后才知道出现问题,而是应该主动监控尽快暴露出异常。
- 静态资源加载异常
- 网络环境恶劣
- 运营商劫持
- 文件丢失
| import { subtle } from 'crypto' | |
| import { Base64 } from 'js-base64' | |
| type ServiceAccount = { | |
| private_key_id: string | |
| private_key: string | |
| client_email: string | |
| } |
| /** | |
| * Get a Google auth token given service user credentials. This function | |
| * is a very slightly modified version of the one found at | |
| * https://community.cloudflare.com/t/example-google-oauth-2-0-for-service-accounts-using-cf-worker/258220 | |
| * | |
| * @param {string} user the service user identity, typically of the | |
| * form [user]@[project].iam.gserviceaccount.com | |
| * @param {string} key the private key corresponding to user | |
| * @param {string} scope the scopes to request for this token, a | |
| * listing of available scopes is provided at |
| function interceptNetworkRequests(ee) { | |
| const open = XMLHttpRequest.prototype.open; | |
| const send = XMLHttpRequest.prototype.send; | |
| const isRegularXHR = open.toString().indexOf('native code') !== -1; | |
| // don't hijack if already hijacked - this will mess up with frameworks like Angular with zones | |
| // we work if we load first there which we can. | |
| if (isRegularXHR) { |
| addEventListener('fetch', event => { | |
| event.respondWith(handleRequest(event)) | |
| }) | |
| /** | |
| * Entry point of the worker | |
| */ | |
| async function handleRequest(event) { | |
| try { | |
| // Get the JWT |
Author: Ari Lerner.
AngularJS offers a single framework that can be used to build dynamic, client-centric applications. It provides: