change default new remote browser template

Signed-off-by: RonniSkansing <rskansing@gmail.com>
This commit is contained in:
RonniSkansing committed 2026-09-12 23:11:26 +02:00
1 parent ff694f8bc7
commit 81a712c3b9
1 file changed
+22 -66
+22 -66
View File
@@ -64,75 +64,31 @@
$: modalText = getModalText('Remote Browser', modalMode);
function defaultScript() {
return `var s = newSession({ headless: true });
return `const s = newSession();
var IN = {
credentials: 'credentials',
otp: 'otp'
};
s.navigate("https://example.com/login");
var OUT = {
ready: 'ready',
otpRequired: 'otp_required',
done: 'done',
failed: 'failed'
};
var SEL = {
username: 'input[name="username"]',
password: 'input[name="password"]',
otp: 'input[name="otp"]',
submit: 'button[type="submit"]',
error: '.error-message'
};
s.navigate('https://portal.example.internal/login');
s.waitVisible(SEL.username);
emit(OUT.ready);
function handleCredentials() {
return retry({ max: 3, wait: 500 }, function() {
var creds = waitForEvent(IN.credentials);
s.states({
error: () => s.visible(".error"),
login: () => s.visible("input[name='email']"),
done: () => s.visible(".logout")
}).run({
login: () => {
const creds = waitForEvent("credentials");
submitData(creds);
s.sendKeys(SEL.username, creds.username);
s.sendKeys(SEL.password, creds.password);
s.click(SEL.submit);
var r = s.race({
otp: { urlContains: '/verify-otp' },
home: { urlContains: '/dashboard' },
error: { visible: SEL.error }
});
if (r.key === 'error') { emit(OUT.failed, 'bad_credentials'); return false; }
return r.key;
});
}
function handleOTP() {
return retry({ max: 5 }, function() {
s.waitVisible(SEL.otp);
emit(OUT.otpRequired);
var o = waitForEvent(IN.otp);
submitData(o);
s.sendKeys(SEL.otp, o.otp);
s.click(SEL.submit);
var r = s.race({
home: { urlContains: '/dashboard' },
error: { visible: SEL.error }
});
if (r.key === 'error') { emit(OUT.failed, 'bad_otp'); return false; }
return r.key;
});
}
var phase = handleCredentials();
if (phase === 'otp') phase = handleOTP();
if (phase === 'home') {
s.capture({ domains: ['example.internal'] });
emit(OUT.done);
}
s.sendKeys("input[name='email']", creds.username);
s.sendKeys("input[name='password']", creds.password);
s.click("button[type='submit']");
},
error: () => {
emit("failed", {});
},
done: (loop) => {
s.capture({ domains: ["example.com"] });
emit("done", {});
loop.stop();
}
});
s.keepAlive();
`;