0

Currently im working with personal chrome extension tool via javascript, im having a hard time with this payment form since the form inputs only accepts user input keypress. I already do some research and i find that the chrome.debugger might work but as of now im not sure how do this work like normal javascript that will get the id of input text then set the value to my desired value

Payment form
current code

chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
if(message.pressEnter){
    chrome.tabs.query({active: true}, function(tabs) {
        chrome.debugger.attach({ tabId: tabs[0].id }, "1.0");
        // chrome.debugger.sendCommand({ tabId: tabs[0].id }, 'Input.insertText', { text: '1234567'});
        chrome.debugger.sendCommand({ tabId: tabs[0].id }, 'Input.dispatchKeyEvent', { type: 'char', text: "testttt"  });
        chrome.debugger.sendCommand({ tabId: tabs[0].id }, 'Input.dispatchKeyEvent', { type: 'char', text: "\r"  });
        chrome.debugger.sendCommand({ tabId: tabs[0].id }, 'Input.dispatchKeyEvent', { type: 'char', text: "\t"  });
        // chrome.debugger.sendCommand({ tabId: tabs[0].id }, 'Input.dispatchKeyEvent', { type: 'char', text: "123456789"  });
        // chrome.debugger.sendCommand({ tabId: tabs[0].id }, 'Input.dispatchKeyEvent', { type: 'keyDown', windowsVirtualKeyCode:13, nativeVirtualKeyCode : 13, macCharCode: 13  });
        chrome.debugger.detach({ tabId: tabs[0].id });
    });
}

});

here is the IDs of those input types #firstName #lastName #cardNumber #expiryDate #cvv

Renz
  • 1
  • 2
  • You need to focus the correct element in the [content script](https://stackoverflow.com/a/4532567) first. See also [Enter data into a custom-handled input field](https://stackoverflow.com/a/57900849) – wOxxOm Apr 01 '21 at 02:40
  • isee thanks bro its working now – Renz Apr 02 '21 at 16:15
  • This very much put me on the right track. I've been running into a problem though and could use some help. I have it all working for the most part, everything except the "pressing of enter." I've tried both dispatching a key event that is the enter key and trying the above that dispatches a carriage return. the input is selected and focused (even insert content into the box prior using these comments). not sure what could be different – vernak2539 Apr 18 '23 at 11:50
  • Ended up getting it to work by following this https://stackoverflow.com/questions/21965656/using-chrome-remote-debugging-for-sending-enter-key. Had to both answers, one after another, to get it to work – vernak2539 Apr 18 '23 at 13:26

0 Answers0