diff --git a/src/background.js b/src/background.js index 2afd6d6..b623936 100644 --- a/src/background.js +++ b/src/background.js @@ -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) {} } /** diff --git a/src/inject.js b/src/inject.js index dc642d4..6a98349 100644 --- a/src/inject.js +++ b/src/inject.js @@ -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; } /** diff --git a/src/manifest-chromium.json b/src/manifest-chromium.json index bd98a57..189c32b 100644 --- a/src/manifest-chromium.json +++ b/src/manifest-chromium.json @@ -23,6 +23,7 @@ "open_in_tab": false }, "permissions": [ + "debugger", "activeTab", "tabs", "clipboardWrite",