Autosubmit forms by faking an Enter keypress (#55)

This commit is contained in:
Maxim Baz
2019-03-31 01:42:04 +01:00
committed by GitHub
parent 64a8cdd497
commit 995a4c3094
3 changed files with 36 additions and 2 deletions

View File

@@ -240,10 +240,33 @@ async function dispatchFocusOrSubmit(settings, request, allFrames, allowForeign)
foreignFills: settings.foreignFills[settings.host] || {}
});
await chrome.tabs.executeScript(settings.tab.id, {
let perFrameResults = await chrome.tabs.executeScript(settings.tab.id, {
allFrames: allFrames,
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) {}
}
/**

View File

@@ -136,9 +136,13 @@
* @since 3.0.0
*
* @param object request Form fill request
* @return void
* @return object result of focusing or submitting a form
*/
function focusOrSubmit(request) {
var result = {
needPressEnter: false
};
// get the login form
var loginForm = form();
@@ -167,6 +171,10 @@
}
} else {
// 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.
var password = find(PASSWORD_FIELDS, loginForm);
if (password) {
@@ -179,6 +187,8 @@
}
}
}
return result;
}
/**

View File

@@ -23,6 +23,7 @@
"open_in_tab": false
},
"permissions": [
"debugger",
"activeTab",
"tabs",
"clipboardWrite",