OpenAdapt icon indicating copy to clipboard operation
OpenAdapt copied to clipboard

Implement Chrome Extension

Open abrichr opened this issue 2 years ago • 6 comments

Certain use cases (e.g. SalesForce, LinkedIn) would greatly benefit from reading and writing website markup and the DOM (i.e. by simplifying tokenization of screenshots).

  1. Implement a Chrome Plugin that sends and receives messages from PuterBot via native messaging: https://developer.chrome.com/docs/extensions/mv3/nativeMessaging/ . On every change to the Document Object Model (DOM) of the currently opened page, the extension should send a message to PuterBot.

  2. Implement an adapter in PuterBot to receive and store the messages with https://github.com/Rayquaza01/nativemessaging. To start with, this can look something like this:

browser.py:

import nativemessaging

def main():
    # based on https://github.com/Rayquaza01/nativemessaging#sample
    reply_num = 0
    while True:
        message = nativemessaging.get_message()
        print(message)
        nativemessaging.send_message(nativemessaging.encode_message(str(reply_num))
        reply_num += 1
if __name__ == "__main__":
    main()

In the extension:

// from https://github.com/Rayquaza01/nativemessaging#sample

function onReceived(response) {
    console.log(response);
}

// runtime.connectNative
var port = browser.runtime.connectNative("application_name");
port.onMessage.addListener(onReceived);
port.postMessage("hello");


// runtime.sendNativeMessage
browser.runtime.sendNativeMessage("puterbot", document).then(onReceived);

// based on https://stackoverflow.com/questions/8882502/how-to-track-dom-change-in-chrome-extension

let observer = new MutationObserver(mutations => {
    for(let mutation of mutations) {
        browser.runtime.sendNativeMessage("puterbot", mutation).then(onReceived);
    }
});
observer.observe(document, { childList: true, subtree: true });

Once this is working, we will want to add the necessary functionality to record.py.

abrichr avatar May 01 '23 02:05 abrichr

Regarding MutationObserver: https://stackoverflow.com/questions/20383356/mutation-observer-is-undefined It is only supported in Internet Explorer 11.

Currently Figuring out an alternative for Chrome.

KrishPatel13 avatar Jun 07 '23 13:06 KrishPatel13

It is only supported in Internet Explorer 11.

Are you sure? https://developer.chrome.com/blog/detect-dom-changes-with-mutation-observers/

abrichr avatar Jun 17 '23 16:06 abrichr

Some Notes regarding Chrome Extension: https://docs.google.com/presentation/d/106AXW3sBe7-7E-zIggnMnaUKUXWAj_aAuSxBspTDcGk/edit?usp=sharing

KrishPatel13 avatar Jul 03 '23 05:07 KrishPatel13

Link to information on publishing extension: https://developer.chrome.com/docs/webstore/publish/

KrishPatel13 avatar Jul 12 '23 15:07 KrishPatel13

https://github.com/OpenAdaptAI/OpenAdapt/pull/364

abrichr avatar Aug 11 '23 18:08 abrichr

This issue shall be closed as completed if this PR gets successfully merged! @abrichr

KrishPatel13 avatar Jul 14 '24 15:07 KrishPatel13