跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

browser.js

240 行 · 7.8 KB历史下载
1/*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2019 The noVNC authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
5 *
6 * See README.md for usage and integration instructions.
7 *
8 * Browser feature support detection
9 */
10
11import * as Log from './logging.js';
12import Base64 from '../base64.js';
13
14// Touch detection
15export let isTouchDevice = ('ontouchstart' in document.documentElement) ||
16 // required for Chrome debugger
17 (document.ontouchstart !== undefined) ||
18 // required for MS Surface
19 (navigator.maxTouchPoints > 0) ||
20 (navigator.msMaxTouchPoints > 0);
21window.addEventListener('touchstart', function onFirstTouch() {
22 isTouchDevice = true;
23 window.removeEventListener('touchstart', onFirstTouch, false);
24}, false);
25
26
27// The goal is to find a certain physical width, the devicePixelRatio
28// brings us a bit closer but is not optimal.
29export let dragThreshold = 10 * (window.devicePixelRatio || 1);
30
31let _supportsCursorURIs = false;
32
33try {
34 const target = document.createElement('canvas');
35 target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
36
37 if (target.style.cursor.indexOf("url") === 0) {
38 Log.Info("Data URI scheme cursor supported");
39 _supportsCursorURIs = true;
40 } else {
41 Log.Warn("Data URI scheme cursor not supported");
42 }
43} catch (exc) {
44 Log.Error("Data URI scheme cursor test exception: " + exc);
45}
46
47export const supportsCursorURIs = _supportsCursorURIs;
48
49let _hasScrollbarGutter = true;
50try {
51 // Create invisible container
52 const container = document.createElement('div');
53 container.style.visibility = 'hidden';
54 container.style.overflow = 'scroll'; // forcing scrollbars
55 document.body.appendChild(container);
56
57 // Create a div and place it in the container
58 const child = document.createElement('div');
59 container.appendChild(child);
60
61 // Calculate the difference between the container's full width
62 // and the child's width - the difference is the scrollbars
63 const scrollbarWidth = (container.offsetWidth - child.offsetWidth);
64
65 // Clean up
66 container.parentNode.removeChild(container);
67
68 _hasScrollbarGutter = scrollbarWidth != 0;
69} catch (exc) {
70 Log.Error("Scrollbar test exception: " + exc);
71}
72export const hasScrollbarGutter = _hasScrollbarGutter;
73
74export let supportsWebCodecsH264Decode = false;
75
76async function _checkWebCodecsH264DecodeSupport() {
77 if (!('VideoDecoder' in window)) {
78 return false;
79 }
80
81 // We'll need to make do with some placeholders here
82 const config = {
83 codec: 'avc1.42401f',
84 codedWidth: 1920,
85 codedHeight: 1080,
86 optimizeForLatency: true,
87 };
88
89 let support = await VideoDecoder.isConfigSupported(config);
90 if (!support.supported) {
91 return false;
92 }
93
94 // Firefox incorrectly reports supports for H.264 under some
95 // circumstances, so we need to actually test a real frame
96 // https://bugzilla.mozilla.org/show_bug.cgi?id=1932392
97
98 const data = new Uint8Array(Base64.decode(
99 'AAAAAWdCwBTZnpuAgICgAAADACAAAAZB4oVNAAAAAWjJYyyAAAABBgX//4Hc' +
100 'Rem95tlIt5Ys2CDZI+7veDI2NCAtIGNvcmUgMTY0IHIzMTA4IDMxZTE5Zjkg' +
101 'LSBILjI2NC9NUEVHLTQgQVZDIGNvZGVjIC0gQ29weWxlZnQgMjAwMy0yMDIz' +
102 'IC0gaHR0cDovL3d3dy52aWRlb2xhbi5vcmcveDI2NC5odG1sIC0gb3B0aW9u' +
103 'czogY2FiYWM9MCByZWY9NSBkZWJsb2NrPTE6MDowIGFuYWx5c2U9MHgxOjB4' +
104 'MTExIG1lPWhleCBzdWJtZT04IHBzeT0xIHBzeV9yZD0xLjAwOjAuMDAgbWl4' +
105 'ZWRfcmVmPTEgbWVfcmFuZ2U9MTYgY2hyb21hX21lPTEgdHJlbGxpcz0yIDh4' +
106 'OGRjdD0wIGNxbT0wIGRlYWR6b25lPTIxLDExIGZhc3RfcHNraXA9MSBjaHJv' +
107 'bWFfcXBfb2Zmc2V0PS0yIHRocmVhZHM9MSBsb29rYWhlYWRfdGhyZWFkcz0x' +
108 'IHNsaWNlZF90aHJlYWRzPTAgbnI9MCBkZWNpbWF0ZT0xIGludGVybGFjZWQ9' +
109 'MCBibHVyYXlfY29tcGF0PTAgY29uc3RyYWluZWRfaW50cmE9MCBiZnJhbWVz' +
110 'PTAgd2VpZ2h0cD0wIGtleWludD1pbmZpbml0ZSBrZXlpbnRfbWluPTI1IHNj' +
111 'ZW5lY3V0PTQwIGludHJhX3JlZnJlc2g9MCByY19sb29rYWhlYWQ9NTAgcmM9' +
112 'YWJyIG1idHJlZT0xIGJpdHJhdGU9NDAwIHJhdGV0b2w9MS4wIHFjb21wPTAu' +
113 'NjAgcXBtaW49MCBxcG1heD02OSBxcHN0ZXA9NCBpcF9yYXRpbz0xLjQwIGFx' +
114 'PTE6MS4wMACAAAABZYiEBrxmKAAPVccAAS044AA5DRJMnkycJk4TPw=='));
115
116 let gotframe = false;
117 let error = null;
118
119 let decoder = new VideoDecoder({
120 output: (frame) => {
121 gotframe = true;
122 frame.close();
123 },
124 error: (e) => { error = e; },
125 });
126 let chunk = new EncodedVideoChunk({
127 timestamp: 0,
128 type: 'key',
129 data: data,
130 });
131
132 try {
133 decoder.configure(config);
134 decoder.decode(chunk);
135 await decoder.flush();
136 } catch (e) {
137 // Firefox incorrectly throws an exception here
138 // https://bugzilla.mozilla.org/show_bug.cgi?id=1932566
139 error = e;
140 } finally {
141 if (decoder.state !== 'closed') {
142 decoder.close();
143 }
144 }
145
146 // Firefox fails to deliver the error on Windows, so we need to
147 // check if we got a frame instead
148 // https://bugzilla.mozilla.org/show_bug.cgi?id=1932579
149 if (!gotframe) {
150 return false;
151 }
152
153 if (error !== null) {
154 return false;
155 }
156
157 return true;
158}
159supportsWebCodecsH264Decode = await _checkWebCodecsH264DecodeSupport();
160
161/*
162 * The functions for detection of platforms and browsers below are exported
163 * but the use of these should be minimized as much as possible.
164 *
165 * It's better to use feature detection than platform detection.
166 */
167
168/* OS */
169
170export function isMac() {
171 return !!(/mac/i).exec(navigator.platform);
172}
173
174export function isWindows() {
175 return !!(/win/i).exec(navigator.platform);
176}
177
178export function isIOS() {
179 return (!!(/ipad/i).exec(navigator.platform) ||
180 !!(/iphone/i).exec(navigator.platform) ||
181 !!(/ipod/i).exec(navigator.platform));
182}
183
184export function isAndroid() {
185 /* Android sets navigator.platform to Linux :/ */
186 return !!navigator.userAgent.match('Android ');
187}
188
189export function isChromeOS() {
190 /* ChromeOS sets navigator.platform to Linux :/ */
191 return !!navigator.userAgent.match(' CrOS ');
192}
193
194/* Browser */
195
196export function isSafari() {
197 return !!navigator.userAgent.match('Safari/...') &&
198 !navigator.userAgent.match('Chrome/...') &&
199 !navigator.userAgent.match('Chromium/...') &&
200 !navigator.userAgent.match('Epiphany/...');
201}
202
203export function isFirefox() {
204 return !!navigator.userAgent.match('Firefox/...') &&
205 !navigator.userAgent.match('Seamonkey/...');
206}
207
208export function isChrome() {
209 return !!navigator.userAgent.match('Chrome/...') &&
210 !navigator.userAgent.match('Chromium/...') &&
211 !navigator.userAgent.match('Edg/...') &&
212 !navigator.userAgent.match('OPR/...');
213}
214
215export function isChromium() {
216 return !!navigator.userAgent.match('Chromium/...');
217}
218
219export function isOpera() {
220 return !!navigator.userAgent.match('OPR/...');
221}
222
223export function isEdge() {
224 return !!navigator.userAgent.match('Edg/...');
225}
226
227/* Engine */
228
229export function isGecko() {
230 return !!navigator.userAgent.match('Gecko/...');
231}
232
233export function isWebKit() {
234 return !!navigator.userAgent.match('AppleWebKit/...') &&
235 !navigator.userAgent.match('Chrome/...');
236}
237
238export function isBlink() {
239 return !!navigator.userAgent.match('Chrome/...');
240}