Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix #9

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions content/js/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@
};

let messageHandler = {
"BlueFox.Dispatch": async (object) => {
log(object);
"BlueFox.Dispatch": async (message, connector) => {
log(message.object);
let R;
for (let f of object.files) {
for (let f of message.object.files) {
await {
"application/json": async (_) => {
R = await BlueFox.do(JSON.parse(await _.text));
Expand All @@ -204,31 +204,32 @@
}
return R;
},
"BlueFox.Dispatch.Action": async (object) => {
log("BlueFox.Dispatch.Action", JSON.parse(object));
return await BlueFox.do(JSON.parse(object));
"BlueFox.Dispatch.Action": async (message, connector) => {
log("BlueFox.Dispatch.Action", JSON.parse(message.object));
return await BlueFox.do(JSON.parse(message.object));
},
"BlueFox.Dispatch.Script": async (object) => {
log("BlueFox.Dispatch.Script", object);
"BlueFox.Dispatch.Script": async (message, connector) => {
log("BlueFox.Dispatch.Script", message.object);
let R = await sendMessage({
type: "Runtime.evaluate",
object: {
expression: object,
expression: message.object,
objectGroup: "BlueFox-js-lanch",
awaitPromise: true,
returnByValue: true,
},
});
return R;
},
"BlueFox.CaptureWindow": async (object) => {
"BlueFox.CaptureWindow": async (message, connector) => {
log("BlueFox.CaptureWindow", message.object);
let R = await sendMessage({
type: "Page.captureScreenshot",
object: object,
object: message.object,
});
return R;
},
"BlueFox.GetEventListners": async (object) => {
"BlueFox.GetEventListners": async (message, connector) => {
let R = (
await sendMessage({
type: "DOMDebugger.getEventListeners",
Expand All @@ -248,10 +249,10 @@
).listeners;
return R;
},
"BlueFox.GetSelectors": async (object) => {
"BlueFox.GetSelectors": async (message, connector) => {
let R = [];
try {
[...document.querySelectorAll(object.selector)].forEach((_) => {
[...document.querySelectorAll(message.object.selector)].forEach((_) => {
try {
R.push({
selector: CssSelectorGenerator.getCssSelector(_),
Expand All @@ -275,10 +276,10 @@
} catch { }
return R;
},
"BlueFox.GetElementProperties": async (object) => {
"BlueFox.GetElementProperties": async (message, connector) => {
let R = {};
try {
let target = document.querySelector(object.selector);
let target = document.querySelector(message.object.selector);
for (let property in target) {
R[property] = target[property];
}
Expand All @@ -293,31 +294,31 @@
} catch { }
return R;
},
"BlueFox.CaptureDOMSnapshot": async (object) => {
"BlueFox.CaptureDOMSnapshot": async (message, connector) => {
let R = await sendMessage({
type: "DOMSnapshot.captureSnapshot",
object: object,
object: message.object,
});
return R;
},
"BlueFoxScript.AddEventListener": async (object) => {
"BlueFoxScript.AddEventListener": async (message, connector) => {
try {
let R = [];
[...document.querySelectorAll(object.selector)].forEach((_) => {
[...document.querySelectorAll(message.object.selector)].forEach((_) => {
let selector = CssSelectorGenerator.getCssSelector(_);
let uuid = crypto.randomUUID();
_.addEventListener(
object.event_type,
message.object.event_type,
(event) => {
object.connector.postMessage(
connector.postMessage(
Object.assign(
object.message,
message,
{
object: {
uuid: object.uuid,
uuid: message.object.uuid,
object: {
uuid: uuid,
type: object.type,
type: message.object.type,
event: (() => {
try {
return Object.assign(
Expand All @@ -328,7 +329,7 @@
);
} catch (e) {
return {
type: object.event_type,
type: message.object.event_type,
target: selector,
};
}
Expand Down Expand Up @@ -372,10 +373,8 @@
connector.onMessage.addListener(async (message) => {
try {
let R = await messageHandler[message.type](
Object.assign(message.object, {
message: message,
connector: connector,
})
message,
connector,
);
connector.postMessage({
uuid: message.uuid,
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "^.,.^ BlueFox",
"version": "0.3.1",
"version": "0.3.2",
"description": "Agile Web Automation Software for Time-Starved Professionals",
"host_permissions": [
"<all_urls>"
Expand Down
Loading