Autosubmit forms by faking an Enter keypress (#55)
This commit is contained in:
@@ -240,10 +240,33 @@ async function dispatchFocusOrSubmit(settings, request, allFrames, allowForeign)
|
|||||||
foreignFills: settings.foreignFills[settings.host] || {}
|
foreignFills: settings.foreignFills[settings.host] || {}
|
||||||
});
|
});
|
||||||
|
|
||||||
await chrome.tabs.executeScript(settings.tab.id, {
|
let perFrameResults = await chrome.tabs.executeScript(settings.tab.id, {
|
||||||
allFrames: allFrames,
|
allFrames: allFrames,
|
||||||
code: `window.browserpass.focusOrSubmit(${JSON.stringify(request)});`
|
code: `window.browserpass.focusOrSubmit(${JSON.stringify(request)});`
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// if necessary, dispatch Enter keypress to autosubmit the form
|
||||||
|
// currently only works on Chromium and requires debugger permission
|
||||||
|
try {
|
||||||
|
for (let frame of perFrameResults) {
|
||||||
|
if (frame.needPressEnter) {
|
||||||
|
chrome.debugger.attach({ tabId: settings.tab.id }, "1.2");
|
||||||
|
for (let type of ["keyDown", "keyUp"]) {
|
||||||
|
chrome.debugger.sendCommand(
|
||||||
|
{ tabId: settings.tab.id },
|
||||||
|
"Input.dispatchKeyEvent",
|
||||||
|
{
|
||||||
|
type: type,
|
||||||
|
windowsVirtualKeyCode: 13,
|
||||||
|
nativeVirtualKeyCode: 13
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
chrome.debugger.detach({ tabId: settings.tab.id });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -136,9 +136,13 @@
|
|||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
*
|
||||||
* @param object request Form fill request
|
* @param object request Form fill request
|
||||||
* @return void
|
* @return object result of focusing or submitting a form
|
||||||
*/
|
*/
|
||||||
function focusOrSubmit(request) {
|
function focusOrSubmit(request) {
|
||||||
|
var result = {
|
||||||
|
needPressEnter: false
|
||||||
|
};
|
||||||
|
|
||||||
// get the login form
|
// get the login form
|
||||||
var loginForm = form();
|
var loginForm = form();
|
||||||
|
|
||||||
@@ -167,6 +171,10 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// There is no submit button.
|
// There is no submit button.
|
||||||
|
if (request.autoSubmit) {
|
||||||
|
// signal background script that we want it to press Enter for us
|
||||||
|
result.needPressEnter = true;
|
||||||
|
}
|
||||||
// We need to keep focus somewhere within the form, so that Enter hopefully submits the form.
|
// We need to keep focus somewhere within the form, so that Enter hopefully submits the form.
|
||||||
var password = find(PASSWORD_FIELDS, loginForm);
|
var password = find(PASSWORD_FIELDS, loginForm);
|
||||||
if (password) {
|
if (password) {
|
||||||
@@ -179,6 +187,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
"open_in_tab": false
|
"open_in_tab": false
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
"debugger",
|
||||||
"activeTab",
|
"activeTab",
|
||||||
"tabs",
|
"tabs",
|
||||||
"clipboardWrite",
|
"clipboardWrite",
|
||||||
|
Reference in New Issue
Block a user