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

Fix unwrapping of eval result array. #33

Merged
merged 1 commit into from
Oct 19, 2022
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
8 changes: 4 additions & 4 deletions addon/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ async function evalInTab(tabId: number, frameId: number, code: string): Promise<
chrome.tabs.executeScript(tabId, {
frameId,
code: `!!window.eval(decodeURIComponent("${encodeURIComponent(code)}"))`
}, (result) => {
}, (resultArr) => {
resolve([{
result,
result: resultArr[0],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sammacbeth looks good I think, so since we're converting the "eval" result to a boolean value I guess we can be sure we'll always get back exactly one result in MV3, if I understand the docs correctly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code path is only for MV2, which returns an array.

frameId,
}]);
})
Expand Down Expand Up @@ -82,7 +82,7 @@ chrome.runtime.onMessage.addListener(
const tabId = sender.tab.id;
const frameId = sender.frameId;
if (enableLogs) {
console.groupCollapsed(`${msg.type} from ${sender.origin || new URL(sender.url).origin}}`);
console.groupCollapsed(`${msg.type} from ${sender.origin || sender.url}`);
console.log(msg, sender);
console.groupEnd();
}
Expand All @@ -106,7 +106,7 @@ chrome.runtime.onMessage.addListener(
case "eval":
evalInTab(tabId, frameId, msg.code).then(([result]) => {
if (enableLogs) {
console.groupCollapsed(`eval result for ${sender.origin}`);
console.groupCollapsed(`eval result for ${sender.origin || sender.url}`);
console.log(msg.code, result.result);
console.groupEnd();
}
Expand Down
Loading