forked from OpenAdaptAI/OpenAdapt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Krish Patel
committed
May 19, 2023
1 parent
958efaa
commit 10a55f6
Showing
9 changed files
with
82 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,32 @@ | ||
/** | ||
the background.js file listens for messages from the content script, and | ||
sends them to PuterBot via native messaging | ||
sends them to OpenAdapt via native messaging | ||
*/ | ||
|
||
chrome.runtime.onMessageExternal.addListener(function(message, sender, sendResponse) { | ||
if (sender.id !== chrome.runtime.id) { | ||
return; | ||
} | ||
// Connect to the native messaging host | ||
let port = chrome.runtime.connectNative("com.openadapt.domlistener"); | ||
|
||
// Receive messages from the native messaging host | ||
port.onMessage.addListener(onReceived); | ||
|
||
// Send initial message to the native messaging host | ||
port.postMessage("hello"); | ||
|
||
// Send the message to PuterBot | ||
chrome.runtime.sendNativeMessage("puterbot", message, function(response) { | ||
console.log(response); | ||
}); | ||
// Handle received messages | ||
function onReceived(response) { | ||
console.log(response); | ||
} | ||
|
||
// Listen for messages from the content script | ||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||
// Forward the message to the native messaging host | ||
port.postMessage(message); | ||
}); | ||
|
||
// Listen for DOM changes in the active tab | ||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { | ||
if (changeInfo.status === "complete") { | ||
// Inject content script to the updated tab | ||
chrome.tabs.executeScript(tabId, { file: "content.js" }); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
import json | ||
""" Module for the browser native messaging host. """ | ||
import nativemessaging | ||
|
||
def main(): | ||
messages = [] | ||
|
||
def main() -> None: | ||
""" | ||
Main function for the browser native messaging host. | ||
""" | ||
reply_num = 0 | ||
while True: | ||
# Receive a message from the Chrome Extension | ||
message = nativemessaging.get_message() | ||
if not message: | ||
break | ||
print(message) | ||
nativemessaging.send_message(nativemessaging.encode_message(str(reply_num))) | ||
reply_num += 1 | ||
|
||
# Parse the message as JSON | ||
message_data = json.loads(message) | ||
|
||
# Store the message in a list | ||
messages.append(message_data) | ||
|
||
# Do something with the collected messages | ||
print(messages) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@echo off | ||
python -u "P:\OpenAdapt AI - MLDS AI\cloned_repo\OpenAdapt\native_chrome_extension\browser.py" |
9 changes: 9 additions & 0 deletions
9
native_chrome_extension/com.openadapt.domlistener_chrome.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "com.openadapt.domlistener", | ||
"description": "OpenAdapt Native Messaging Host", | ||
"path": "P:\\OpenAdapt AI - MLDS AI\\cloned_repo\\OpenAdapt\\native_chrome_extension\\com.openadapt.domlistener.bat", | ||
"type": "stdio", | ||
"allowed_origins": [ | ||
"chrome-extension://fipijfheidmdeingpecoiflbjefbnfjn/" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"name": "browser", | ||
"description": "PuterBot DOM Listener", | ||
"path": "./browser.py", | ||
"name": "com.openadapt.domlistener", | ||
"description": "OpenAdapt Native Messaging Host", | ||
"path": "browser.py", | ||
"type": "stdio", | ||
"allowed_origins": [ | ||
"chrome-extension://aeedjbflenakjffcnhodfddbphbnpemf/" | ||
"chrome-extension://fipijfheidmdeingpecoiflbjefbnfjn/" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>OpenAdapt DOM Listener</title> | ||
</head> | ||
|
||
<body> | ||
<h1>PuterBot DOM Listener</h1> | ||
<p>Extension is actively listening for DOM changes.</p> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ sqlalchemy==1.4.43 | |
torch==2.0.0 | ||
tqdm==4.64.0 | ||
transformers==4.28.1 | ||
nativemessaging==1.0.1 |