@usecrow/client 0.1.24 → 0.1.26

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.
@@ -0,0 +1,120 @@
1
+ (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(`._wrapper_gf8tz_1{position:fixed;top:0;right:0;bottom:0;left:0;z-index:2147483641;cursor:wait;overflow:hidden;display:none}._cursor_1dgwb_2{position:absolute;width:var(--cursor-size, 75px);height:var(--cursor-size, 75px);pointer-events:none;z-index:10000}._cursorBorder_1dgwb_10{position:absolute;width:100%;height:100%;background:linear-gradient(45deg,#39b6ff,#bd45fb);-webkit-mask-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");mask-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");-webkit-mask-size:100% 100%;mask-size:100% 100%;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;transform-origin:center;transform:rotate(-135deg) scale(1.2);margin-left:-10px;margin-top:-18px}._cursorFilling_1dgwb_25{position:absolute;width:100%;height:100%;background:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3e%3cdefs%3e%3c/defs%3e%3cg%20xmlns='http://www.w3.org/2000/svg'%20style='filter:%20drop-shadow(light-dark(rgba(0,%200,%200,%200.4),%20rgba(237,%20237,%20237,%200.4))%203px%204px%204px);'%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='%23ffffff'%20stroke='none'%20style='fill:%20%23ffffff;'/%3e%3c/g%3e%3c/svg%3e");background-size:100% 100%;background-repeat:no-repeat;transform-origin:center;transform:rotate(-135deg) scale(1.2);margin-left:-10px;margin-top:-18px}._cursorRipple_1dgwb_39{position:absolute;width:100%;height:100%;pointer-events:none;margin-left:-50%;margin-top:-50%}._cursorRipple_1dgwb_39:after{content:"";opacity:0;position:absolute;top:0;right:0;bottom:0;left:0;border:4px solid rgba(57,182,255,1);border-radius:50%}._cursor_1dgwb_2._clicking_1dgwb_57 ._cursorRipple_1dgwb_39:after{animation:_cursor-ripple_1dgwb_1 .3s ease-out forwards}@keyframes _cursor-ripple_1dgwb_1{0%{transform:scale(0);opacity:1}to{transform:scale(2);opacity:0}}`)),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
+ var v = (s) => {
3
+ throw TypeError(s);
4
+ };
5
+ var w = (s, t, e) => t.has(s) || v("Cannot " + e);
6
+ var r = (s, t, e) => (w(s, t, "read from private field"), e ? e.call(s) : t.get(s)), l = (s, t, e) => t.has(s) ? v("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(s) : t.set(s, e), o = (s, t, e, i) => (w(s, t, "write to private field"), i ? i.call(s, e) : t.set(s, e), e), g = (s, t, e) => (w(s, t, "access private method"), e);
7
+ import { Motion as b } from "ai-motion";
8
+ function y() {
9
+ const s = ["dark", "dark-mode", "theme-dark", "night", "night-mode"], t = document.documentElement, e = document.body || document.documentElement;
10
+ for (const m of s)
11
+ if (t.classList.contains(m) || e != null && e.classList.contains(m))
12
+ return !0;
13
+ const i = t.getAttribute("data-theme");
14
+ return !!(i != null && i.toLowerCase().includes("dark"));
15
+ }
16
+ function E(s) {
17
+ const t = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(s);
18
+ return t ? {
19
+ r: parseInt(t[1]),
20
+ g: parseInt(t[2]),
21
+ b: parseInt(t[3])
22
+ } : null;
23
+ }
24
+ function C(s, t = 128) {
25
+ if (!s || s === "transparent" || s.startsWith("rgba(0, 0, 0, 0)"))
26
+ return !1;
27
+ const e = E(s);
28
+ return e ? 0.299 * e.r + 0.587 * e.g + 0.114 * e.b < t : !1;
29
+ }
30
+ function _() {
31
+ const s = window.getComputedStyle(document.documentElement), t = window.getComputedStyle(document.body || document.documentElement), e = s.backgroundColor, i = t.backgroundColor;
32
+ return C(i) ? !0 : i === "transparent" || i.startsWith("rgba(0, 0, 0, 0)") ? C(e) : !1;
33
+ }
34
+ function L() {
35
+ try {
36
+ return !!(y() || _());
37
+ } catch (s) {
38
+ return console.warn("Error determining if page is dark:", s), !1;
39
+ }
40
+ }
41
+ const D = "_wrapper_gf8tz_1", P = {
42
+ wrapper: D
43
+ }, A = "_cursor_1dgwb_2", x = "_cursorBorder_1dgwb_10", M = "_cursorFilling_1dgwb_25", B = "_cursorRipple_1dgwb_39", R = "_clicking_1dgwb_57", d = {
44
+ cursor: A,
45
+ cursorBorder: x,
46
+ cursorFilling: M,
47
+ cursorRipple: B,
48
+ clicking: R
49
+ };
50
+ var n, a, c, p, h, u, k, f;
51
+ class S {
52
+ constructor() {
53
+ l(this, u);
54
+ l(this, n);
55
+ l(this, a);
56
+ l(this, c);
57
+ l(this, p);
58
+ l(this, h);
59
+ this.shown = !1, this.wrapper = document.createElement("div"), this.motion = new b({
60
+ mode: L() ? "dark" : "light",
61
+ styles: {
62
+ position: "absolute",
63
+ inset: "0"
64
+ }
65
+ }), o(this, n, document.createElement("div")), o(this, a, 0), o(this, c, 0), o(this, p, 0), o(this, h, 0), this.wrapper.id = "page-agent-runtime_simulator-mask", this.wrapper.className = P.wrapper, this.wrapper.setAttribute("data-browser-use-ignore", "true"), this.wrapper.appendChild(this.motion.element), this.motion.autoResize(this.wrapper), this.wrapper.addEventListener("click", (t) => {
66
+ t.stopPropagation(), t.preventDefault();
67
+ }), this.wrapper.addEventListener("mousedown", (t) => {
68
+ t.stopPropagation(), t.preventDefault();
69
+ }), this.wrapper.addEventListener("mouseup", (t) => {
70
+ t.stopPropagation(), t.preventDefault();
71
+ }), this.wrapper.addEventListener("mousemove", (t) => {
72
+ t.stopPropagation(), t.preventDefault();
73
+ }), this.wrapper.addEventListener("wheel", (t) => {
74
+ t.stopPropagation(), t.preventDefault();
75
+ }), this.wrapper.addEventListener("keydown", (t) => {
76
+ t.stopPropagation(), t.preventDefault();
77
+ }), this.wrapper.addEventListener("keyup", (t) => {
78
+ t.stopPropagation(), t.preventDefault();
79
+ }), g(this, u, k).call(this), document.body.appendChild(this.wrapper), g(this, u, f).call(this), window.addEventListener("PageAgent::MovePointerTo", (t) => {
80
+ const { x: e, y: i } = t.detail;
81
+ this.setCursorPosition(e, i);
82
+ }), window.addEventListener("PageAgent::ClickPointer", (t) => {
83
+ this.triggerClickAnimation();
84
+ });
85
+ }
86
+ setCursorPosition(t, e) {
87
+ o(this, p, t), o(this, h, e);
88
+ }
89
+ triggerClickAnimation() {
90
+ r(this, n).classList.remove(d.clicking), r(this, n).offsetHeight, r(this, n).classList.add(d.clicking);
91
+ }
92
+ show() {
93
+ this.shown || (this.shown = !0, this.motion.start(), this.motion.fadeIn(), this.wrapper.style.display = "block", o(this, a, window.innerWidth / 2), o(this, c, window.innerHeight / 2), o(this, p, r(this, a)), o(this, h, r(this, c)), r(this, n).style.left = `${r(this, a)}px`, r(this, n).style.top = `${r(this, c)}px`);
94
+ }
95
+ hide() {
96
+ this.shown && (this.shown = !1, this.motion.fadeOut(), this.motion.pause(), r(this, n).classList.remove(d.clicking), setTimeout(() => {
97
+ this.wrapper.style.display = "none";
98
+ }, 800));
99
+ }
100
+ dispose() {
101
+ this.motion.dispose(), this.wrapper.remove();
102
+ }
103
+ }
104
+ n = new WeakMap(), a = new WeakMap(), c = new WeakMap(), p = new WeakMap(), h = new WeakMap(), u = new WeakSet(), k = function() {
105
+ r(this, n).className = d.cursor;
106
+ const t = document.createElement("div");
107
+ t.className = d.cursorRipple, r(this, n).appendChild(t);
108
+ const e = document.createElement("div");
109
+ e.className = d.cursorFilling, r(this, n).appendChild(e);
110
+ const i = document.createElement("div");
111
+ i.className = d.cursorBorder, r(this, n).appendChild(i), this.wrapper.appendChild(r(this, n));
112
+ }, f = function() {
113
+ const t = r(this, a) + (r(this, p) - r(this, a)) * 0.2, e = r(this, c) + (r(this, h) - r(this, c)) * 0.2, i = Math.abs(t - r(this, p));
114
+ i > 0 && (i < 2 ? o(this, a, r(this, p)) : o(this, a, t), r(this, n).style.left = `${r(this, a)}px`);
115
+ const m = Math.abs(e - r(this, h));
116
+ m > 0 && (m < 2 ? o(this, c, r(this, h)) : o(this, c, e), r(this, n).style.top = `${r(this, c)}px`), requestAnimationFrame(() => g(this, u, f).call(this));
117
+ };
118
+ export {
119
+ S as SimulatorMask
120
+ };
@@ -0,0 +1,2 @@
1
+ (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(`._wrapper_gf8tz_1{position:fixed;top:0;right:0;bottom:0;left:0;z-index:2147483641;cursor:wait;overflow:hidden;display:none}._cursor_1dgwb_2{position:absolute;width:var(--cursor-size, 75px);height:var(--cursor-size, 75px);pointer-events:none;z-index:10000}._cursorBorder_1dgwb_10{position:absolute;width:100%;height:100%;background:linear-gradient(45deg,#39b6ff,#bd45fb);-webkit-mask-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");mask-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");-webkit-mask-size:100% 100%;mask-size:100% 100%;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;transform-origin:center;transform:rotate(-135deg) scale(1.2);margin-left:-10px;margin-top:-18px}._cursorFilling_1dgwb_25{position:absolute;width:100%;height:100%;background:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3e%3cdefs%3e%3c/defs%3e%3cg%20xmlns='http://www.w3.org/2000/svg'%20style='filter:%20drop-shadow(light-dark(rgba(0,%200,%200,%200.4),%20rgba(237,%20237,%20237,%200.4))%203px%204px%204px);'%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='%23ffffff'%20stroke='none'%20style='fill:%20%23ffffff;'/%3e%3c/g%3e%3c/svg%3e");background-size:100% 100%;background-repeat:no-repeat;transform-origin:center;transform:rotate(-135deg) scale(1.2);margin-left:-10px;margin-top:-18px}._cursorRipple_1dgwb_39{position:absolute;width:100%;height:100%;pointer-events:none;margin-left:-50%;margin-top:-50%}._cursorRipple_1dgwb_39:after{content:"";opacity:0;position:absolute;top:0;right:0;bottom:0;left:0;border:4px solid rgba(57,182,255,1);border-radius:50%}._cursor_1dgwb_2._clicking_1dgwb_57 ._cursorRipple_1dgwb_39:after{animation:_cursor-ripple_1dgwb_1 .3s ease-out forwards}@keyframes _cursor-ripple_1dgwb_1{0%{transform:scale(0);opacity:1}to{transform:scale(2);opacity:0}}`)),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
+ "use strict";var v=s=>{throw TypeError(s)};var w=(s,t,e)=>t.has(s)||v("Cannot "+e);var r=(s,t,e)=>(w(s,t,"read from private field"),e?e.call(s):t.get(s)),h=(s,t,e)=>t.has(s)?v("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),o=(s,t,e,i)=>(w(s,t,"write to private field"),i?i.call(s,e):t.set(s,e),e),g=(s,t,e)=>(w(s,t,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("ai-motion");function y(){const s=["dark","dark-mode","theme-dark","night","night-mode"],t=document.documentElement,e=document.body||document.documentElement;for(const m of s)if(t.classList.contains(m)||e!=null&&e.classList.contains(m))return!0;const i=t.getAttribute("data-theme");return!!(i!=null&&i.toLowerCase().includes("dark"))}function E(s){const t=/rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(s);return t?{r:parseInt(t[1]),g:parseInt(t[2]),b:parseInt(t[3])}:null}function C(s,t=128){if(!s||s==="transparent"||s.startsWith("rgba(0, 0, 0, 0)"))return!1;const e=E(s);return e?.299*e.r+.587*e.g+.114*e.b<t:!1}function _(){const s=window.getComputedStyle(document.documentElement),t=window.getComputedStyle(document.body||document.documentElement),e=s.backgroundColor,i=t.backgroundColor;return C(i)?!0:i==="transparent"||i.startsWith("rgba(0, 0, 0, 0)")?C(e):!1}function L(){try{return!!(y()||_())}catch(s){return console.warn("Error determining if page is dark:",s),!1}}const D="_wrapper_gf8tz_1",P={wrapper:D},M="_cursor_1dgwb_2",A="_cursorBorder_1dgwb_10",S="_cursorFilling_1dgwb_25",x="_cursorRipple_1dgwb_39",B="_clicking_1dgwb_57",u={cursor:M,cursorBorder:A,cursorFilling:S,cursorRipple:x,clicking:B};var n,a,c,l,p,d,b,f;class R{constructor(){h(this,d);h(this,n);h(this,a);h(this,c);h(this,l);h(this,p);this.shown=!1,this.wrapper=document.createElement("div"),this.motion=new k.Motion({mode:L()?"dark":"light",styles:{position:"absolute",inset:"0"}}),o(this,n,document.createElement("div")),o(this,a,0),o(this,c,0),o(this,l,0),o(this,p,0),this.wrapper.id="page-agent-runtime_simulator-mask",this.wrapper.className=P.wrapper,this.wrapper.setAttribute("data-browser-use-ignore","true"),this.wrapper.appendChild(this.motion.element),this.motion.autoResize(this.wrapper),this.wrapper.addEventListener("click",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("mouseup",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("mousemove",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("wheel",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("keydown",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("keyup",t=>{t.stopPropagation(),t.preventDefault()}),g(this,d,b).call(this),document.body.appendChild(this.wrapper),g(this,d,f).call(this),window.addEventListener("PageAgent::MovePointerTo",t=>{const{x:e,y:i}=t.detail;this.setCursorPosition(e,i)}),window.addEventListener("PageAgent::ClickPointer",t=>{this.triggerClickAnimation()})}setCursorPosition(t,e){o(this,l,t),o(this,p,e)}triggerClickAnimation(){r(this,n).classList.remove(u.clicking),r(this,n).offsetHeight,r(this,n).classList.add(u.clicking)}show(){this.shown||(this.shown=!0,this.motion.start(),this.motion.fadeIn(),this.wrapper.style.display="block",o(this,a,window.innerWidth/2),o(this,c,window.innerHeight/2),o(this,l,r(this,a)),o(this,p,r(this,c)),r(this,n).style.left=`${r(this,a)}px`,r(this,n).style.top=`${r(this,c)}px`)}hide(){this.shown&&(this.shown=!1,this.motion.fadeOut(),this.motion.pause(),r(this,n).classList.remove(u.clicking),setTimeout(()=>{this.wrapper.style.display="none"},800))}dispose(){this.motion.dispose(),this.wrapper.remove()}}n=new WeakMap,a=new WeakMap,c=new WeakMap,l=new WeakMap,p=new WeakMap,d=new WeakSet,b=function(){r(this,n).className=u.cursor;const t=document.createElement("div");t.className=u.cursorRipple,r(this,n).appendChild(t);const e=document.createElement("div");e.className=u.cursorFilling,r(this,n).appendChild(e);const i=document.createElement("div");i.className=u.cursorBorder,r(this,n).appendChild(i),this.wrapper.appendChild(r(this,n))},f=function(){const t=r(this,a)+(r(this,l)-r(this,a))*.2,e=r(this,c)+(r(this,p)-r(this,c))*.2,i=Math.abs(t-r(this,l));i>0&&(i<2?o(this,a,r(this,l)):o(this,a,t),r(this,n).style.left=`${r(this,a)}px`);const m=Math.abs(e-r(this,p));m>0&&(m<2?o(this,c,r(this,p)):o(this,c,e),r(this,n).style.top=`${r(this,c)}px`),requestAnimationFrame(()=>g(this,d,f).call(this))};exports.SimulatorMask=R;
package/dist/browser.cjs CHANGED
@@ -1,284 +1 @@
1
- 'use strict';
2
-
3
- var pageController = require('@page-agent/page-controller');
4
-
5
- // src/browser.ts
6
-
7
- // src/browserUse.ts
8
- var injectedPageController = null;
9
- var PageControllerModule = null;
10
- function setPageController(PC) {
11
- injectedPageController = PC;
12
- }
13
- async function getPageController() {
14
- if (injectedPageController) {
15
- return injectedPageController;
16
- }
17
- if (!PageControllerModule) {
18
- try {
19
- PageControllerModule = await import('@page-agent/page-controller');
20
- } catch (error) {
21
- throw new Error(
22
- 'PageController not available. Either import from "@usecrow/client/browser" or install @page-agent/page-controller as a dependency.'
23
- );
24
- }
25
- }
26
- return PageControllerModule.PageController;
27
- }
28
- var CrowBrowserUse = class {
29
- constructor(config) {
30
- this.pageController = null;
31
- this.sessionId = null;
32
- this.maxSteps = 20;
33
- this.config = config;
34
- }
35
- /**
36
- * Initialize PageController with non-blocking pointer
37
- */
38
- async initPageController() {
39
- if (this.pageController) {
40
- return this.pageController;
41
- }
42
- try {
43
- const PageController2 = await getPageController();
44
- this.pageController = new PageController2({
45
- enableMask: true,
46
- viewportExpansion: 500,
47
- highlightLabelOpacity: 0,
48
- // Hide numbered labels from users
49
- highlightOpacity: 0
50
- // Hide highlight boxes from users
51
- });
52
- await this.pageController.showMask();
53
- const mask = this.pageController.mask;
54
- if (mask?.wrapper) {
55
- mask.wrapper.style.pointerEvents = "none";
56
- }
57
- console.log("[CrowBrowserUse] PageController initialized with non-blocking pointer");
58
- return this.pageController;
59
- } catch (error) {
60
- console.error("[CrowBrowserUse] Failed to import @page-agent/page-controller:", error);
61
- throw new Error(
62
- "Failed to initialize browser automation. Make sure @page-agent/page-controller is installed."
63
- );
64
- }
65
- }
66
- /**
67
- * Execute a browser automation task
68
- */
69
- async execute(task) {
70
- console.log("[CrowBrowserUse] Starting task:", task);
71
- try {
72
- const controller = await this.initPageController();
73
- const startResponse = await this.startSession(task);
74
- this.sessionId = startResponse.session_id;
75
- this.maxSteps = startResponse.max_steps;
76
- console.log("[CrowBrowserUse] Session started:", this.sessionId);
77
- let stepCount = 0;
78
- let lastActionResult;
79
- while (stepCount < this.maxSteps) {
80
- stepCount++;
81
- const browserState = await controller.getBrowserState();
82
- const stepResponse = await this.processStep(browserState, lastActionResult);
83
- if (stepResponse.done) {
84
- console.log("[CrowBrowserUse] Task completed:", stepResponse.message);
85
- await this.cleanup();
86
- return {
87
- status: stepResponse.success ? "success" : "error",
88
- data: {
89
- message: stepResponse.message,
90
- steps: stepCount
91
- },
92
- error: stepResponse.success ? void 0 : stepResponse.message
93
- };
94
- }
95
- if (stepResponse.error) {
96
- console.error("[CrowBrowserUse] Error:", stepResponse.error);
97
- await this.cleanup();
98
- return {
99
- status: "error",
100
- error: stepResponse.error
101
- };
102
- }
103
- if (stepResponse.action) {
104
- lastActionResult = await this.executeAction(controller, stepResponse.action);
105
- console.log(`[CrowBrowserUse] Step ${stepCount}:`, lastActionResult);
106
- }
107
- if (stepResponse.reflection) {
108
- console.log("[CrowBrowserUse] Reflection:", stepResponse.reflection.next_goal);
109
- }
110
- }
111
- await this.cleanup();
112
- return {
113
- status: "error",
114
- error: `Task incomplete after ${this.maxSteps} steps`
115
- };
116
- } catch (error) {
117
- console.error("[CrowBrowserUse] Error:", error);
118
- await this.cleanup();
119
- return {
120
- status: "error",
121
- error: error instanceof Error ? error.message : String(error)
122
- };
123
- }
124
- }
125
- /**
126
- * Start a browser-use session on the server
127
- */
128
- async startSession(task) {
129
- const response = await fetch(`${this.config.apiUrl}/api/browser-use/start`, {
130
- method: "POST",
131
- headers: { "Content-Type": "application/json" },
132
- body: JSON.stringify({
133
- product_id: this.config.productId,
134
- task
135
- })
136
- });
137
- if (!response.ok) {
138
- const error = await response.json().catch(() => ({ detail: "Unknown error" }));
139
- throw new Error(error.detail || `Failed to start session: ${response.status}`);
140
- }
141
- return response.json();
142
- }
143
- /**
144
- * Process a step on the server
145
- */
146
- async processStep(browserState, actionResult) {
147
- const response = await fetch(`${this.config.apiUrl}/api/browser-use/step`, {
148
- method: "POST",
149
- headers: { "Content-Type": "application/json" },
150
- body: JSON.stringify({
151
- session_id: this.sessionId,
152
- product_id: this.config.productId,
153
- browser_state: browserState,
154
- action_result: actionResult
155
- })
156
- });
157
- if (!response.ok) {
158
- const error = await response.json().catch(() => ({ detail: "Unknown error" }));
159
- throw new Error(error.detail || `Failed to process step: ${response.status}`);
160
- }
161
- return response.json();
162
- }
163
- /**
164
- * Execute an action using PageController
165
- */
166
- async executeAction(controller, action) {
167
- const actionName = Object.keys(action)[0];
168
- const actionParams = action[actionName];
169
- try {
170
- switch (actionName) {
171
- case "click_element_by_index": {
172
- const result = await controller.clickElement(actionParams.index);
173
- return result.message;
174
- }
175
- case "input_text": {
176
- const result = await controller.inputText(
177
- actionParams.index,
178
- actionParams.text
179
- );
180
- return result.message;
181
- }
182
- case "select_dropdown_option": {
183
- const result = await controller.selectOption(
184
- actionParams.index,
185
- actionParams.text
186
- );
187
- return result.message;
188
- }
189
- case "scroll": {
190
- const result = await controller.scroll({
191
- down: actionParams.down,
192
- numPages: actionParams.num_pages,
193
- pixels: actionParams.pixels,
194
- index: actionParams.index
195
- });
196
- return result.message;
197
- }
198
- case "scroll_horizontally": {
199
- const result = await controller.scrollHorizontally({
200
- right: actionParams.right,
201
- pixels: actionParams.pixels,
202
- index: actionParams.index
203
- });
204
- return result.message;
205
- }
206
- case "wait": {
207
- const seconds = actionParams.seconds || 1;
208
- await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
209
- return `Waited ${seconds} seconds`;
210
- }
211
- case "done": {
212
- return "Task completed";
213
- }
214
- default:
215
- return `Unknown action: ${actionName}`;
216
- }
217
- } catch (error) {
218
- return `Action failed: ${error instanceof Error ? error.message : String(error)}`;
219
- }
220
- }
221
- /**
222
- * Cleanup resources
223
- */
224
- async cleanup() {
225
- if (this.pageController) {
226
- try {
227
- await this.pageController.hideMask();
228
- await this.pageController.cleanUpHighlights();
229
- this.pageController.dispose();
230
- } catch (error) {
231
- console.warn("[CrowBrowserUse] Cleanup error:", error);
232
- }
233
- this.pageController = null;
234
- }
235
- if (this.sessionId) {
236
- try {
237
- await fetch(`${this.config.apiUrl}/api/browser-use/end`, {
238
- method: "POST",
239
- headers: { "Content-Type": "application/json" },
240
- body: JSON.stringify({
241
- session_id: this.sessionId,
242
- product_id: this.config.productId
243
- })
244
- });
245
- } catch (error) {
246
- }
247
- this.sessionId = null;
248
- }
249
- }
250
- /**
251
- * Stop the current task
252
- */
253
- async stop() {
254
- await this.cleanup();
255
- }
256
- };
257
-
258
- // src/browser.ts
259
- setPageController(pageController.PageController);
260
- function createBrowserUseTool(config) {
261
- return async (args) => {
262
- const instruction = args.instruction || args.instruction;
263
- if (!instruction) {
264
- return {
265
- status: "error",
266
- error: "Missing instruction parameter for browser_use tool"
267
- };
268
- }
269
- const browserUse = new CrowBrowserUse({
270
- productId: config.productId,
271
- apiUrl: config.apiUrl
272
- });
273
- return browserUse.execute(instruction);
274
- };
275
- }
276
-
277
- Object.defineProperty(exports, "PageController", {
278
- enumerable: true,
279
- get: function () { return pageController.PageController; }
280
- });
281
- exports.CrowBrowserUse = CrowBrowserUse;
282
- exports.createBrowserUseTool = createBrowserUseTool;
283
- //# sourceMappingURL=browser.cjs.map
284
- //# sourceMappingURL=browser.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./PageController-GcMFZYwU.cjs"),r=require("./browserUse-BOc9kyBK.cjs");r.setPageController(s.PageController);function n(e){return async o=>{const t=o.instruction||o.instruction;return t?new r.CrowBrowserUse({productId:e.productId,apiUrl:e.apiUrl}).execute(t):{status:"error",error:"Missing instruction parameter for browser_use tool"}}}exports.PageController=s.PageController;exports.CrowBrowserUse=r.CrowBrowserUse;exports.createBrowserUseTool=n;