-
Notifications
You must be signed in to change notification settings - Fork 22
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
Use Messenger in more content script places (Native Editor, Dev Tools) #1460
Conversation
628d29e
to
985d453
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diff best seen without whitespace changes
DETECT_FRAMEWORK_VERSIONS | ||
); | ||
export const withDetectFrameworkVersions = createSendScriptMessage< | ||
FrameworkMeta[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This type was changed because withDetectFrameworkVersions
had an assertion to FrameworkMeta
in the only place where it was used.
queueReactivateTab, | ||
"Reactivation queue failed for some tabs" | ||
); | ||
void forEachTab(queueReactivateTab); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the messenger now supports notifications natively (pixiebrix/webext-messenger#24), notifyTabs
was replaced by a simple loop + call of the method, which means the errors are no longer logged together.
import "@/contentScript/devTools"; | ||
import "@/contentScript/contextMenus"; | ||
import addContentScriptListener from "@/contentScript/backgroundProtocol"; | ||
import { handleNavigate } from "@/contentScript/lifecycle"; | ||
import addExecutorListener from "@/contentScript/executor"; | ||
import "@/messaging/external"; | ||
import "@/contentScript/script"; | ||
import "@/vendors/notify"; | ||
import { markReady, updateTabInfo } from "@/contentScript/context"; | ||
import { initTelemetry } from "@/telemetry/events"; | ||
import "@/contentScript/uipath"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the unassigned imports removed by this PR were only used to register the listeners and have been double-checked for other side-effects (but not their sub-dependencies)
import { BlockConfig } from "@/blocks/types"; | ||
import { cloneDeep } from "lodash"; | ||
import ConsoleLogger from "@/tests/ConsoleLogger"; | ||
import { SerializableResponse } from "@/messaging/protocol"; | ||
|
||
if (isContentScript()) { | ||
addListenerForUpdateSelectedElement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the only "active" code and it's been moved to @/contentScript.ts
if (openerTabId != null) { | ||
console.debug(`Setting opener tabId: ${openerTabId}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused, removed
"QUEUE_REACTIVATE_TAB" | ||
"QUEUE_REACTIVATE_TAB", | ||
{ isNotification: true } | ||
); | ||
export const reactivateTab = getContentScriptMethod("REACTIVATE_TAB"); | ||
export const reactivateTab = getContentScriptMethod("REACTIVATE_TAB", { | ||
isNotification: true, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods were added in #1329 but now they're real "notifications" 🎉
export async function updateDynamicElement({ | ||
extensionPoint: extensionPointConfig, | ||
extension: extensionConfig, | ||
}: DynamicDefinition): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where possible, I also added return values for https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md
The rule is useful because it ensures we don't change a function’s signature by mistake.
INSTALLED_EXTENSIONS: getInstalledIds, | ||
CHECK_AVAILABLE: checkAvailable, | ||
HANDLE_NAVIGATE: handleNavigate, | ||
SHOW_NOTIFICATION: showNotification, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test report
Seen in the console
- REACTIVATE_TAB
- RUN_SINGLE_BLOCK
- READ_SELECTED
- DETECT_FRAMEWORKS
- CLEAR_DYNAMIC_ELEMENTS - seen in console but I'm not sure I saw it working
- UPDATE_DYNAMIC_ELEMENT
- ENABLE_OVERLAY - I don't know what this does 🤔
- DISABLE_OVERLAY
- INSTALLED_EXTENSIONS
- CHECK_AVAILABLE
- HANDLE_NAVIGATE
- SHOW_NOTIFICATION
- RUN_READER
Unable to test
- INSERT_PANEL - behind beta flag?
- INSERT_BUTTON - behind beta flag?
- UIPATH_INIT - I'm not sure whether I can use this
- UIPATH_GET_PROCESSES - Same
- SEARCH_WINDOW - Unused. It appears in
devTools/Locator
but that file isn't used anywhere. - RUN_READER_BLOCK - unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The beta flag you can always fake by hard-coding the check for the beta flag
INSERT_BUTTON
: this is what is used when adding a button the add Menu Item / Button flow in the page editor
I'll add the UiPath ones to the testing list for 1.4.0. They have to be tested on Windows with a UiPath local install
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENABLE_OVERLAY is used to show an overlay over an element you have selected when using SelectorSelectorWidget
message: "Ran content menu item action", | ||
className: "success", | ||
}); | ||
void showNotification(target, "Ran content menu item action", "success"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to change the API of the showNotification method. Having multiple arguments of the same type is error prone (if the arguments are swapped, TypeScript won't complain). Also, using the object will allow us to expose more options in the future
Could we go back to the object-based method signature? Alternatively, we could have the message as an argument and then put className in an options object parameter
- Avoid error-prone method signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple arguments of the same type is error prone
Agreed, but this is not the case, className
has a union type:
pixiebrix-extension/src/contentScript/notify.ts
Lines 20 to 23 in d6890dc
export async function showNotification( | |
message: string, | |
className: "error" | "info" | "success" | |
): Promise<void> { |
I reverted the change anyway though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argh sorry the commit push had failed somehow and I merged without the change. I included the change in the next PR https://github.com/pixiebrix/pixiebrix-extension/pull/1477/files#diff-660a48b387ef0f402e92201cc396679f79e0a52a43b6e6960f5ff07ef756d5b3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fregante see comment about the showNotification API
Otherwise, let's get this merged in so we'll get some days of testing amongst the dev team before the 1.4.0 submission
Intent
liftContentScript
as part of: Prevent context-specific code from being imported in the wrong context #669notifyContentScripts
with Messenger #1329Context
Many of these handlers are just forwarders (which haven't been implemented yet), but making this change first prepares the content script API (it will be final) without having to test forwarding on top of that.
Next
Past Messenger PRs
notifyContentScripts
with Messenger #1329handleMenuAction
#1319sendTab
#1315webext-messenger
(for background functions and messages) #1258