Skip to content

update manifest.json with test keyboard shortcuts#1359

Draft
henih wants to merge 3 commits into
devfrom
927-a11y
Draft

update manifest.json with test keyboard shortcuts#1359
henih wants to merge 3 commits into
devfrom
927-a11y

Conversation

@henih

@henih henih commented Nov 8, 2024

Copy link
Copy Markdown
Contributor

resolves: #927

Blocking: Supposedly the function for the custom keyboard shortcut should be implemented in the service_worker file, but after the script runs it disappears from the file.

Hi @imilka , do you have any ideas why this might be happening?
I tried following the implementation instructions from here for MV3.

Related articles:
https://blog.shahednasser.com/how-to-add-keyboard-shortcuts-in-a-chrome-extension/#adding-a-standard-command
https://issues.chromium.org/issues/40756021
https://developer.chrome.com/docs/extensions/reference/api/commands

@henih henih self-assigned this Nov 8, 2024
@henih
henih requested a review from imilka November 12, 2024 12:50
@imilka

imilka commented Nov 12, 2024

Copy link
Copy Markdown
Contributor

Hi @henih! May I see your implementation of keyboard shortcuts in service worker as well? I can only see the manifest part right now if I'm correct.

@henih

henih commented Nov 13, 2024

Copy link
Copy Markdown
Contributor Author

Hi @imilka , I haven't even got that far because I got already stuck on the sample code disappearing.

// manifest.js
"commands": {
	"_execute_action": {
		"suggested_key": "Ctrl+Shift+L",
		"description": "Toggle dark body"
	},
}

//  background_bundle.js 
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
    target: {tabId: tab.id},
    function: toggleDark
});

function toggleDark () {
    if (!document.body.getAttribute('data-ext-dark')) {
        document.body.setAttribute('data-ext-dark', true);
        document.body.style.backgroundColor = '#000';
        document.body.style.color = '#fff';
    } else {
        document.body.setAttribute('data-ext-dark', false);
        document.body.style.backgroundColor = '#fff';
        document.body.style.color = '#000';
    }
}

@imilka

imilka commented Nov 13, 2024

Copy link
Copy Markdown
Contributor

@henih Am I right that you are trying to edit background.bundle.js?

Also, could you tell me what is that you are trying to achieve?
If you need to execute a script in a tab which would be triggered by custom keyboard shortcut, I got you a sample here:
https://github.com/witty-works/browser-extension/tree/927-a11y-shortcuts-sample
Let me know if that helps!

@henih
henih removed the request for review from imilka November 20, 2024 14:40
@lsmith77 lsmith77 assigned lsmith77 and unassigned henih Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants