codex-in-chrome 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +362 -2
- package/assets/logo.png +0 -0
- package/assets/logo.svg +9 -0
- package/bin/cli.mjs +41 -0
- package/dist/server.mjs +39416 -0
- package/extension/background.js +2222 -0
- package/extension/dom.js +178 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/manifest.json +35 -0
- package/extension/overlay.js +278 -0
- package/package.json +43 -6
- package/rules/AGENTS.md +10 -0
- package/scripts/install.mjs +271 -0
- package/skills/codex-in-chrome/SKILL.md +34 -0
package/extension/dom.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Deep DOM helpers shared by every injected snippet. They walk the document,
|
|
2
|
+
// open and closed shadow roots, and same-origin iframes, give elements an
|
|
3
|
+
// accessible-style name, and map element boxes to top-level viewport
|
|
4
|
+
// coordinates (the frame CDP mouse events use).
|
|
5
|
+
(() => {
|
|
6
|
+
if (window.__codexDom) return;
|
|
7
|
+
const HUD = '__codex_pilot_hud_host__';
|
|
8
|
+
|
|
9
|
+
function shadowOf(el) {
|
|
10
|
+
if (el.shadowRoot) return el.shadowRoot;
|
|
11
|
+
// Closed shadow roots are only reachable through the extension API, and
|
|
12
|
+
// in practice they only appear on custom elements (tag names with "-").
|
|
13
|
+
if (!el.localName.includes('-')) return null;
|
|
14
|
+
try {
|
|
15
|
+
return globalThis.chrome?.dom?.openOrClosedShadowRoot?.(el) || null;
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function roots(doc = document, out = []) {
|
|
22
|
+
out.push(doc);
|
|
23
|
+
for (const el of doc.querySelectorAll('*')) {
|
|
24
|
+
if (el.id === HUD) continue;
|
|
25
|
+
const sr = shadowOf(el);
|
|
26
|
+
if (sr) roots(sr, out);
|
|
27
|
+
if (el.tagName === 'IFRAME' || el.tagName === 'FRAME') {
|
|
28
|
+
let d = null;
|
|
29
|
+
try {
|
|
30
|
+
d = el.contentDocument;
|
|
31
|
+
} catch {}
|
|
32
|
+
if (d?.documentElement) roots(d, out);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function all(sel) {
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const r of roots()) for (const el of r.querySelectorAll(sel)) out.push(el);
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function one(sel) {
|
|
45
|
+
const fast = document.querySelector(sel);
|
|
46
|
+
if (fast) return fast;
|
|
47
|
+
for (const r of roots()) {
|
|
48
|
+
if (r === document) continue;
|
|
49
|
+
const el = r.querySelector(sel);
|
|
50
|
+
if (el) return el;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const byUid = uid => one(`[data-codex-uid="${CSS.escape(uid)}"]`);
|
|
56
|
+
|
|
57
|
+
// Box in top-level viewport CSS pixels (adds same-origin iframe offsets).
|
|
58
|
+
function box(el) {
|
|
59
|
+
const r = el.getBoundingClientRect();
|
|
60
|
+
let x = r.left;
|
|
61
|
+
let y = r.top;
|
|
62
|
+
let win = el.ownerDocument.defaultView;
|
|
63
|
+
while (win && win !== window) {
|
|
64
|
+
let f = null;
|
|
65
|
+
try {
|
|
66
|
+
f = win.frameElement;
|
|
67
|
+
} catch {}
|
|
68
|
+
if (!f) break;
|
|
69
|
+
const fr = f.getBoundingClientRect();
|
|
70
|
+
x += fr.left + f.clientLeft;
|
|
71
|
+
y += fr.top + f.clientTop;
|
|
72
|
+
win = win.parent;
|
|
73
|
+
}
|
|
74
|
+
return {x, y, width: r.width, height: r.height, cx: x + r.width / 2, cy: y + r.height / 2};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function atPoint(x, y) {
|
|
78
|
+
let el = document.elementFromPoint(x, y);
|
|
79
|
+
for (let i = 0; el && i < 12; i++) {
|
|
80
|
+
const sr = shadowOf(el);
|
|
81
|
+
if (sr?.elementFromPoint) {
|
|
82
|
+
const inner = sr.elementFromPoint(x, y);
|
|
83
|
+
if (inner && inner !== el) {
|
|
84
|
+
el = inner;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (el.tagName === 'IFRAME') {
|
|
89
|
+
let d = null;
|
|
90
|
+
try {
|
|
91
|
+
d = el.contentDocument;
|
|
92
|
+
} catch {}
|
|
93
|
+
if (d) {
|
|
94
|
+
const r = el.getBoundingClientRect();
|
|
95
|
+
x -= r.left + el.clientLeft;
|
|
96
|
+
y -= r.top + el.clientTop;
|
|
97
|
+
const inner = d.elementFromPoint(x, y);
|
|
98
|
+
if (inner) {
|
|
99
|
+
el = inner;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
return el;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const clean = s => String(s || '').trim().replace(/\s+/g, ' ');
|
|
110
|
+
|
|
111
|
+
// Roughly the accessible name: aria-label, aria-labelledby, <label>, text,
|
|
112
|
+
// placeholder/title/alt, then icon alt text, then name/id.
|
|
113
|
+
function label(el) {
|
|
114
|
+
let s = clean(el.getAttribute('aria-label'));
|
|
115
|
+
if (!s) {
|
|
116
|
+
const ids = el.getAttribute('aria-labelledby');
|
|
117
|
+
const rootNode = el.getRootNode();
|
|
118
|
+
if (ids && rootNode.getElementById) {
|
|
119
|
+
s = clean(ids.split(/\s+/).map(id => rootNode.getElementById(id)?.innerText || '').join(' '));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (!s && el.labels?.length) s = clean(el.labels[0].innerText);
|
|
123
|
+
const tag = el.tagName;
|
|
124
|
+
if (!s && tag !== 'INPUT' && tag !== 'TEXTAREA' && tag !== 'SELECT') s = clean(el.innerText);
|
|
125
|
+
if (!s) s = clean(el.getAttribute('placeholder') || el.getAttribute('title') || el.getAttribute('alt'));
|
|
126
|
+
if (!s && tag === 'INPUT' && /^(submit|button|reset)$/i.test(el.type)) s = clean(el.value);
|
|
127
|
+
if (!s) {
|
|
128
|
+
const icon = el.querySelector?.('img[alt], [aria-label], svg title');
|
|
129
|
+
if (icon) s = clean(icon.getAttribute('alt') || icon.getAttribute('aria-label') || icon.textContent);
|
|
130
|
+
}
|
|
131
|
+
if (!s) s = clean(el.getAttribute('name') || el.id);
|
|
132
|
+
return s;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Element, then its scrollable ancestors (crossing shadow roots and frames),
|
|
136
|
+
// ending with the page.
|
|
137
|
+
function* scrollChain(el) {
|
|
138
|
+
const seen = new Set();
|
|
139
|
+
for (let n = el; n; ) {
|
|
140
|
+
if (n.nodeType === 1 && !seen.has(n)) {
|
|
141
|
+
seen.add(n);
|
|
142
|
+
const st = (n.ownerDocument.defaultView || window).getComputedStyle(n);
|
|
143
|
+
const canY = /(auto|scroll|overlay)/.test(st.overflowY) && n.scrollHeight > n.clientHeight + 1;
|
|
144
|
+
const canX = /(auto|scroll|overlay)/.test(st.overflowX) && n.scrollWidth > n.clientWidth + 1;
|
|
145
|
+
if (canY || canX) yield n;
|
|
146
|
+
}
|
|
147
|
+
if (n.parentElement) n = n.parentElement;
|
|
148
|
+
else if (n.getRootNode?.().host) n = n.getRootNode().host;
|
|
149
|
+
else {
|
|
150
|
+
let f = null;
|
|
151
|
+
try {
|
|
152
|
+
f = n.ownerDocument?.defaultView?.frameElement;
|
|
153
|
+
} catch {}
|
|
154
|
+
n = f || null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
yield document.scrollingElement || document.documentElement;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const INTERACTIVE =
|
|
161
|
+
'a, button, input:not([type="hidden"]), textarea, select, summary, [role="button"], [role="link"], [role="textbox"], [role="searchbox"], [role="combobox"], [role="checkbox"], [role="radio"], [role="switch"], [role="tab"], [role="menuitem"], [role="menuitemcheckbox"], [role="option"], [role="slider"], [contenteditable=""], [contenteditable="true"], [tabindex="0"]';
|
|
162
|
+
|
|
163
|
+
// Same-origin iframes that are still loading (cross-origin ones are skipped).
|
|
164
|
+
function framesPending() {
|
|
165
|
+
let n = 0;
|
|
166
|
+
for (const f of document.querySelectorAll('iframe')) {
|
|
167
|
+
const src = f.getAttribute('src') || '';
|
|
168
|
+
if (!src || src.startsWith('javascript:')) continue;
|
|
169
|
+
try {
|
|
170
|
+
const d = f.contentDocument;
|
|
171
|
+
if (d && (d.readyState === 'loading' || (d.URL === 'about:blank' && !src.startsWith('about:')))) n++;
|
|
172
|
+
} catch {}
|
|
173
|
+
}
|
|
174
|
+
return n;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
window.__codexDom = {framesPending, roots, all, one, byUid, box, atPoint, label, shadowOf, scrollChain, INTERACTIVE};
|
|
178
|
+
})();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": 3,
|
|
3
|
+
"name": "Codex in Chrome",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Lets OpenAI Codex work in your own Chrome inside its own tab group: visible cursor, forms, uploads, background tab recording and screenshots.",
|
|
6
|
+
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApXYVdwhn7G7jMMDrr5TuNWgZfFF9Y74gvlNqa2qNaF6Qcp2H8ZY30TNXT1JrKAu48WrH6c6F/WqZOLjL5BI9Wqw2VCVa49flmnBCOO/yI8nj26Y1z0imtj4Nsoam7b+FrEazBGi/pUP5BVj0tbEFftAIr24sucudpeiR633smE5cv0sZ+7V/O0wbSAWy/z1p6h03acHCmTpdOzxnd9sMqfzkvUUakyOKdTLFa7/uvywevoii6GS+MWJbw7bywDXUiKuptJVae/ZnXETA2EOG9DPmQ6XpL1DSXdd1fdvWTarFr3e8+mt6KamZypr1Cq6KqgE96FSFKCPfEUY9a5ervQIDAQAB",
|
|
7
|
+
"icons": {
|
|
8
|
+
"16": "icons/icon-16.png",
|
|
9
|
+
"32": "icons/icon-32.png",
|
|
10
|
+
"48": "icons/icon-48.png",
|
|
11
|
+
"128": "icons/icon-128.png"
|
|
12
|
+
},
|
|
13
|
+
"permissions": [
|
|
14
|
+
"tabs",
|
|
15
|
+
"tabGroups",
|
|
16
|
+
"scripting",
|
|
17
|
+
"alarms",
|
|
18
|
+
"debugger",
|
|
19
|
+
"downloads"
|
|
20
|
+
],
|
|
21
|
+
"host_permissions": [
|
|
22
|
+
"<all_urls>"
|
|
23
|
+
],
|
|
24
|
+
"action": {
|
|
25
|
+
"default_title": "Codex in Chrome (click to reconnect)",
|
|
26
|
+
"default_icon": {
|
|
27
|
+
"16": "icons/icon-16.png",
|
|
28
|
+
"32": "icons/icon-32.png"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"background": {
|
|
32
|
+
"service_worker": "background.js",
|
|
33
|
+
"type": "module"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
if (window.__codexPilotOverlay) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const HOST_ID = '__codex_pilot_hud_host__';
|
|
7
|
+
let host = document.getElementById(HOST_ID);
|
|
8
|
+
if (!host) {
|
|
9
|
+
host = document.createElement('div');
|
|
10
|
+
host.id = HOST_ID;
|
|
11
|
+
host.style.cssText =
|
|
12
|
+
'position:fixed;inset:0;pointer-events:none;z-index:2147483647;margin:0;padding:0;border:0;background:transparent;';
|
|
13
|
+
(document.documentElement || document.body).appendChild(host);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const shadow = host.shadowRoot || host.attachShadow({mode: 'open'});
|
|
17
|
+
shadow.innerHTML = `
|
|
18
|
+
<style>
|
|
19
|
+
:host { all: initial; }
|
|
20
|
+
.root {
|
|
21
|
+
position: fixed;
|
|
22
|
+
inset: 0;
|
|
23
|
+
pointer-events: none;
|
|
24
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
25
|
+
}
|
|
26
|
+
.banner {
|
|
27
|
+
position: fixed;
|
|
28
|
+
top: 10px;
|
|
29
|
+
left: 50%;
|
|
30
|
+
transform: translateX(-50%);
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
gap: 8px;
|
|
34
|
+
padding: 6px 14px;
|
|
35
|
+
border-radius: 999px;
|
|
36
|
+
background: rgba(15, 23, 42, 0.88);
|
|
37
|
+
border: 1px solid rgba(110, 231, 183, 0.45);
|
|
38
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
|
|
39
|
+
color: #f8fafc;
|
|
40
|
+
font-size: 12px;
|
|
41
|
+
font-weight: 600;
|
|
42
|
+
letter-spacing: 0.01em;
|
|
43
|
+
backdrop-filter: blur(8px);
|
|
44
|
+
transition: opacity 220ms ease;
|
|
45
|
+
opacity: 0.94;
|
|
46
|
+
}
|
|
47
|
+
.dot {
|
|
48
|
+
width: 8px;
|
|
49
|
+
height: 8px;
|
|
50
|
+
border-radius: 50%;
|
|
51
|
+
background: #34d399;
|
|
52
|
+
box-shadow: 0 0 10px #34d399;
|
|
53
|
+
animation: pulse 1.5s infinite ease-in-out;
|
|
54
|
+
}
|
|
55
|
+
@keyframes pulse {
|
|
56
|
+
0%, 100% { transform: scale(1); opacity: 1; }
|
|
57
|
+
50% { transform: scale(1.35); opacity: 0.65; }
|
|
58
|
+
}
|
|
59
|
+
.bracket-box {
|
|
60
|
+
position: fixed;
|
|
61
|
+
pointer-events: none;
|
|
62
|
+
opacity: 0;
|
|
63
|
+
transition: opacity 150ms ease, left 120ms ease, top 120ms ease, width 120ms ease, height 120ms ease;
|
|
64
|
+
border-radius: 6px;
|
|
65
|
+
background: rgba(52, 211, 153, 0.08);
|
|
66
|
+
box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.85), 0 0 18px rgba(16, 185, 129, 0.35);
|
|
67
|
+
}
|
|
68
|
+
.cursor-wrap {
|
|
69
|
+
position: fixed;
|
|
70
|
+
left: 0;
|
|
71
|
+
top: 0;
|
|
72
|
+
transform: translate3d(40px, 40px, 0);
|
|
73
|
+
will-change: transform;
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: flex-start;
|
|
76
|
+
gap: 6px;
|
|
77
|
+
opacity: 0;
|
|
78
|
+
transition: opacity 180ms ease;
|
|
79
|
+
}
|
|
80
|
+
.cursor-svg {
|
|
81
|
+
width: 26px;
|
|
82
|
+
height: 26px;
|
|
83
|
+
filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.45));
|
|
84
|
+
transform-origin: 3px 3px;
|
|
85
|
+
}
|
|
86
|
+
.cursor-label {
|
|
87
|
+
margin-top: 16px;
|
|
88
|
+
padding: 4px 10px;
|
|
89
|
+
border-radius: 999px;
|
|
90
|
+
background: linear-gradient(135deg, rgba(5, 150, 105, 0.95), rgba(16, 163, 127, 0.95));
|
|
91
|
+
color: #ffffff;
|
|
92
|
+
font-size: 11px;
|
|
93
|
+
font-weight: 600;
|
|
94
|
+
white-space: nowrap;
|
|
95
|
+
max-width: 240px;
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
text-overflow: ellipsis;
|
|
98
|
+
box-shadow: 0 4px 14px rgba(5, 150, 105, 0.35);
|
|
99
|
+
border: 1px solid rgba(255, 255, 255, 0.25);
|
|
100
|
+
}
|
|
101
|
+
.rec {
|
|
102
|
+
position: fixed;
|
|
103
|
+
top: 10px;
|
|
104
|
+
right: 12px;
|
|
105
|
+
display: none;
|
|
106
|
+
align-items: center;
|
|
107
|
+
gap: 6px;
|
|
108
|
+
padding: 4px 10px;
|
|
109
|
+
border-radius: 999px;
|
|
110
|
+
background: rgba(15, 23, 42, 0.88);
|
|
111
|
+
color: #fecaca;
|
|
112
|
+
font-size: 11px;
|
|
113
|
+
font-weight: 700;
|
|
114
|
+
letter-spacing: 0.06em;
|
|
115
|
+
}
|
|
116
|
+
.rec i {
|
|
117
|
+
width: 8px;
|
|
118
|
+
height: 8px;
|
|
119
|
+
border-radius: 50%;
|
|
120
|
+
background: #ef4444;
|
|
121
|
+
animation: pulse 1.2s infinite ease-in-out;
|
|
122
|
+
}
|
|
123
|
+
.ripple {
|
|
124
|
+
position: fixed;
|
|
125
|
+
width: 14px;
|
|
126
|
+
height: 14px;
|
|
127
|
+
margin-left: -7px;
|
|
128
|
+
margin-top: -7px;
|
|
129
|
+
border-radius: 50%;
|
|
130
|
+
border: 2.5px solid #34d399;
|
|
131
|
+
background: rgba(52, 211, 153, 0.25);
|
|
132
|
+
animation: rippleAnim 520ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
|
|
133
|
+
}
|
|
134
|
+
@keyframes rippleAnim {
|
|
135
|
+
0% { transform: scale(0.5); opacity: 1; }
|
|
136
|
+
100% { transform: scale(3.4); opacity: 0; }
|
|
137
|
+
}
|
|
138
|
+
</style>
|
|
139
|
+
<div class="root">
|
|
140
|
+
<div class="banner" id="banner"><span class="dot"></span><span id="banner-text">Codex in Chrome • Active</span></div>
|
|
141
|
+
<div class="rec" id="rec"><i></i>REC</div>
|
|
142
|
+
<div class="bracket-box" id="bracket"></div>
|
|
143
|
+
<div class="cursor-wrap" id="cursor">
|
|
144
|
+
<svg class="cursor-svg" viewBox="0 0 28 28" fill="none">
|
|
145
|
+
<defs>
|
|
146
|
+
<linearGradient id="codexGrad" x1="0" y1="0" x2="28" y2="28" gradientUnits="userSpaceOnUse">
|
|
147
|
+
<stop offset="0%" stop-color="#34d399"/>
|
|
148
|
+
<stop offset="100%" stop-color="#10a37f"/>
|
|
149
|
+
</linearGradient>
|
|
150
|
+
</defs>
|
|
151
|
+
<path d="M4 3L23 12.5L14.5 15L11.5 24L4 3Z" fill="url(#codexGrad)" stroke="#0F172A" stroke-width="2" stroke-linejoin="round"/>
|
|
152
|
+
</svg>
|
|
153
|
+
<div class="cursor-label" id="cursor-label">Codex</div>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
`;
|
|
157
|
+
|
|
158
|
+
const cursorEl = shadow.getElementById('cursor');
|
|
159
|
+
const cursorLabelEl = shadow.getElementById('cursor-label');
|
|
160
|
+
const bracketEl = shadow.getElementById('bracket');
|
|
161
|
+
const bannerTextEl = shadow.getElementById('banner-text');
|
|
162
|
+
const rootEl = shadow.querySelector('.root');
|
|
163
|
+
const recEl = shadow.getElementById('rec');
|
|
164
|
+
|
|
165
|
+
function setRecording(on) {
|
|
166
|
+
recEl.style.display = on ? 'flex' : 'none';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let currentX = window.innerWidth * 0.5;
|
|
170
|
+
let currentY = window.innerHeight * 0.4;
|
|
171
|
+
let highlightTimer = null;
|
|
172
|
+
|
|
173
|
+
function setStatus(text) {
|
|
174
|
+
if (text) {
|
|
175
|
+
bannerTextEl.textContent = text;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function showHighlight(rect) {
|
|
180
|
+
if (!rect || rect.width <= 0 || rect.height <= 0) {
|
|
181
|
+
bracketEl.style.opacity = '0';
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const pad = 4;
|
|
185
|
+
bracketEl.style.left = `${rect.x - pad}px`;
|
|
186
|
+
bracketEl.style.top = `${rect.y - pad}px`;
|
|
187
|
+
bracketEl.style.width = `${rect.width + pad * 2}px`;
|
|
188
|
+
bracketEl.style.height = `${rect.height + pad * 2}px`;
|
|
189
|
+
bracketEl.style.opacity = '1';
|
|
190
|
+
clearTimeout(highlightTimer);
|
|
191
|
+
highlightTimer = setTimeout(() => {
|
|
192
|
+
bracketEl.style.opacity = '0';
|
|
193
|
+
}, 1400);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function spawnRipple(x, y) {
|
|
197
|
+
const r = document.createElement('div');
|
|
198
|
+
r.className = 'ripple';
|
|
199
|
+
r.style.left = `${x}px`;
|
|
200
|
+
r.style.top = `${y}px`;
|
|
201
|
+
rootEl.appendChild(r);
|
|
202
|
+
setTimeout(() => r.remove(), 560);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function moveTo(targetX, targetY, label = '', durationMs = 340, rect = null) {
|
|
206
|
+
return new Promise(resolve => {
|
|
207
|
+
cursorEl.style.opacity = '1';
|
|
208
|
+
if (label) {
|
|
209
|
+
cursorLabelEl.textContent = label;
|
|
210
|
+
cursorLabelEl.style.display = 'block';
|
|
211
|
+
setStatus(`Codex • ${label}`);
|
|
212
|
+
} else {
|
|
213
|
+
cursorLabelEl.style.display = 'none';
|
|
214
|
+
}
|
|
215
|
+
if (rect) {
|
|
216
|
+
showHighlight(rect);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const startX = currentX;
|
|
220
|
+
const startY = currentY;
|
|
221
|
+
const dx = targetX - startX;
|
|
222
|
+
const dy = targetY - startY;
|
|
223
|
+
const dist = Math.hypot(dx, dy);
|
|
224
|
+
const dur = dist < 4 ? 30 : Math.min(260, Math.max(110, durationMs));
|
|
225
|
+
const ctrlX = (startX + targetX) / 2 - dy * 0.14;
|
|
226
|
+
const ctrlY = (startY + targetY) / 2 + dx * 0.14;
|
|
227
|
+
const start = performance.now();
|
|
228
|
+
let done = false;
|
|
229
|
+
const finish = () => {
|
|
230
|
+
if (done) return;
|
|
231
|
+
done = true;
|
|
232
|
+
currentX = targetX;
|
|
233
|
+
currentY = targetY;
|
|
234
|
+
cursorEl.style.transform = `translate3d(${targetX}px, ${targetY}px, 0)`;
|
|
235
|
+
resolve({x: targetX, y: targetY});
|
|
236
|
+
};
|
|
237
|
+
// Background tab: nobody sees the animation, rAF doesn't run and timers are
|
|
238
|
+
// throttled to ~1s, so jump straight to the target instead of waiting.
|
|
239
|
+
if (window.__codexInstant || document.visibilityState === 'hidden') {
|
|
240
|
+
finish();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
setTimeout(finish, dur + 120);
|
|
244
|
+
|
|
245
|
+
function step(now) {
|
|
246
|
+
if (done) return;
|
|
247
|
+
const t = Math.min(1, (now - start) / dur);
|
|
248
|
+
const ease = 1 - Math.pow(1 - t, 3);
|
|
249
|
+
const inv = 1 - ease;
|
|
250
|
+
const x = inv * inv * startX + 2 * inv * ease * ctrlX + ease * ease * targetX;
|
|
251
|
+
const y = inv * inv * startY + 2 * inv * ease * ctrlY + ease * ease * targetY;
|
|
252
|
+
currentX = x;
|
|
253
|
+
currentY = y;
|
|
254
|
+
cursorEl.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
255
|
+
if (t < 1) {
|
|
256
|
+
requestAnimationFrame(step);
|
|
257
|
+
} else {
|
|
258
|
+
finish();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
requestAnimationFrame(step);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function clickAt(x, y, label = 'Clicking', rect = null) {
|
|
266
|
+
await moveTo(x, y, label, 200, rect);
|
|
267
|
+
spawnRipple(x, y);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
window.__codexPilotOverlay = {
|
|
271
|
+
setStatus,
|
|
272
|
+
showHighlight,
|
|
273
|
+
spawnRipple,
|
|
274
|
+
moveTo,
|
|
275
|
+
clickAt,
|
|
276
|
+
setRecording,
|
|
277
|
+
};
|
|
278
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "codex-in-chrome",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "codex-in-chrome",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Let OpenAI Codex work in your own Chrome, in its own tab group: an MCP server plus a Chrome extension with 25 browser tools.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"codex-in-chrome": "bin/cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"dist/server.mjs",
|
|
12
|
+
"extension",
|
|
13
|
+
"skills",
|
|
14
|
+
"rules",
|
|
15
|
+
"assets",
|
|
16
|
+
"scripts/install.mjs",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "node scripts/build.mjs",
|
|
25
|
+
"build:extension": "node scripts/build.mjs --extension",
|
|
26
|
+
"test": "npm --prefix server test",
|
|
27
|
+
"test:codex": "npm --prefix server run test:codex",
|
|
28
|
+
"prepack": "node scripts/build.mjs"
|
|
29
|
+
},
|
|
30
|
+
"keywords": ["codex", "openai", "mcp", "chrome", "browser-automation", "chrome-extension"],
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/Sudhanshu5669/codex-in-chrome.git"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/Sudhanshu5669/codex-in-chrome#readme",
|
|
36
|
+
"bugs": "https://github.com/Sudhanshu5669/codex-in-chrome/issues",
|
|
37
|
+
"author": "SinghAbhinav04 and Sudhanshu5669",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"esbuild": "^0.25.0",
|
|
41
|
+
"fflate": "^0.8.2"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/rules/AGENTS.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
## Codex in Chrome
|
|
2
|
+
|
|
3
|
+
When the user asks you to browse, search, fill forms, upload files, debug a web page, or record or screenshot websites, use the `codex-in-chrome` MCP tools (`pilot_*`):
|
|
4
|
+
|
|
5
|
+
1. Work only inside the `"Codex"` tab group of the user's own Chrome. Start with `pilot_start`; never touch the user's other tabs. Agent tabs stay in the background by default so the user can keep working. Use `stealth: true` (or `CODEX_PILOT_STEALTH=1`) on sensitive or anti-bot sites to interact like a real person.
|
|
6
|
+
2. Find elements cheaply: `pilot_snapshot` once per page, or `pilot_snapshot query="login button"` for just the best matches. uids stay valid, so do not re-snapshot before every click. A cross-origin iframe is one `[f7] iframe` line: list it with `pilot_snapshot frame=f7` and use its `f7:e3` uids. If a target is not found, the error lists the closest controls with uids: use one of those.
|
|
7
|
+
3. Act with `pilot_click` (uid/text/selector, or x,y from a screenshot), `pilot_fill` (inputs, rich editors, selects, checkboxes; with no target it types into the focused element), `pilot_press` (combos such as `"ctrl+a Backspace"`), `pilot_drag`, `pilot_scroll`, `pilot_upload`. Use `pilot_wait text=...` instead of fixed sleeps. After clicking a download, `pilot_downloads wait=true` returns the saved path.
|
|
8
|
+
4. Save tokens: actions return only what changed; pass `snapshot: "none"` when you do not need it; chain known steps with `pilot_batch`; use `pilot_read find=...`; screenshots go to files, so use `inline: true` only to look (and `region` to zoom).
|
|
9
|
+
5. Debug with `pilot_logs` (console, or `kind: "network"`), `pilot_eval` (top-level await works) and `pilot_viewport`.
|
|
10
|
+
6. To record what you do, call `pilot_record_start` before the steps and `pilot_record_stop` after, then give the user the file path.
|