Copy, Paste & Select All Hotkeys not working in Browser Source Interact & Docks (macOS) #365
Labels
No labels
area/accessibility
area/dependency
Confirmed
Crash Report
Delayed
Design Issue
Duplicate
Feedback required
Good first issue
kind/bug
kind/cleanup
kind/enhancement
platform/linux
platform/macos
platform/windows
priority/high
Question
Request for Comments
Seeking Other Contributors
Seeking Testers
Won't Fix / By Design
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-obsproject/obs-browser#365
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Operating System Info
macOS 11
Other OS
No response
OBS Studio Version
27.2.4
OBS Studio Version (Other)
No response
OBS Studio Log URL
All
OBS Studio Crash Log URL
No response
Expected Behavior
Using CMD+C, CMD+V & CMD+A should copy, paste and select all respectively.
Current Behavior
Using mouse and contextual menu is the only way to currently do this.
Steps to Reproduce
Anything else we should know?
No response
Note: this was split from #238.
Honestly, this is pretty much expected behaviour. The way hotkeys work on macOS as an operating system is that whatever is in the menu bar takes priority.
To properly fix this, we'd have to ensure OBS knows what context the user is in, and modify the Edit menu to replace the actions of copy/paste/select all with their CEF counterparts.
Unfortunately, I don't know how viable/possible this is. I know CEF in general is very bad at notifying the parent application (in this case OBS) whether it's focused.
The good(?) news is the API to perform the actions themselves does exist as part of CefFrame(), including
Set up OBS Studio and OBS Browser Source on macOS:
Modify the OBS Browser Source plugin:
obs-browser-source.cppfile in a text editor or IDE.Define the custom Edit menu:
obs-browser-source.cppfile, locate thebrowser_source_createfunction.CefMenuModelto represent the custom Edit menu:AddItemmethod. For example:edit_menuas a submenu for the browser source's context menu:Handle user input for the new menu item:
CefMenuModelDelegateand override theExecuteCommandmethod to handle the custom menu commands:browser_source_createfunction, create a new instance of theEditMenuDelegateclass and set it as the delegate for theedit_menu:Trigger the corresponding CEF actions:
ExecuteCommandmethod of theEditMenuDelegateclass, use thecommand_idparameter to determine which action to perform. For example:Compile and test:
The OBS Browser plugin uses CEF internally, but it doesn't expose the source code for the CEF part in a .cpp file. Instead, you'll have to modify the JavaScript code that communicates with the plugin to create a custom context menu with the desired functionality.
To create a custom Edit menu for the OBS Browser Source, follow these steps:
Set up a new local HTML file that will be used as the Browser Source:
Create a new HTML file with the following basic structure:
<html> <head> </head> </html> Save the file locally, e.g., as custom_edit_menu.html. Add an event listener for the context menu to the JavaScript code in the HTML file:php
Copy code
javascript
Copy code
window.addEventListener('contextmenu', (event) => {
event.preventDefault();
// Code to create and display the custom context menu will go here.
});
Create the custom Edit menu using JavaScript:
Inside the event listener, create an HTML element for the custom context menu:
javascript
Copy code
const contextMenu = document.createElement('div');
contextMenu.style.position = 'fixed';
contextMenu.style.left =
${event.clientX}px;contextMenu.style.top =
${event.clientY}px;contextMenu.style.backgroundColor = '#f8f8f8';
contextMenu.style.border = '1px solid #ccc';
contextMenu.style.padding = '8px';
contextMenu.style.zIndex = 9999;
Create menu items for copy, paste, and select all, and add them to the context menu:
javascript
Copy code
const copyItem = document.createElement('button');
copyItem.textContent = 'Copy';
copyItem.onclick = () => {
document.execCommand('copy');
document.body.removeChild(contextMenu);
};
contextMenu.appendChild(copyItem);
const pasteItem = document.createElement('button');
pasteItem.textContent = 'Paste';
pasteItem.onclick = () => {
document.execCommand('paste');
document.body.removeChild(contextMenu);
};
contextMenu.appendChild(pasteItem);
const selectAllItem = document.createElement('button');
selectAllItem.textContent = 'Select All';
selectAllItem.onclick = () => {
document.execCommand('selectAll');
document.body.removeChild(contextMenu);
};
contextMenu.appendChild(selectAllItem);
Display the custom context menu and handle hiding it:
Add the context menu to the document body:
javascript
Copy code
document.body.appendChild(contextMenu);
Add an event listener to hide the context menu when clicking outside of it:
javascript
Copy code
window.addEventListener('click', () => {
if (document.body.contains(contextMenu)) {
document.body.removeChild(contextMenu);
}
});
Set up OBS Studio and the Browser Source:
Open OBS Studio.
Create a new Browser Source.
In the Browser Source properties, set the local file as the source, e.g., custom_edit_menu.html.
With these modifications, you should have a custom context menu with copy, paste, and select all commands in the OBS Browser Source. Note that this approach uses JavaScript's execCommand function, which is now deprecated. You may need to use the Clipboard API.
Set up a new local HTML file that will be used as the Browser Source:
custom_edit_menu.html.Add an event listener for the context menu to the JavaScript code in the HTML file:
window.addEventListener('contextmenu', (event) => {
event.preventDefault();
// Code to create and display the custom context menu will go here.
});
Create the custom Edit menu using JavaScript:
custom_edit_menu.html.is there a possibility that the copy paste is also installed with the hotkey in a next update? The function has otherwise no use for me.
This is a CEF related bug.
please try https://glitch.com/edit/#!/async-clipboard-text in web browser and cef demo such as cefclient, you can find that.
Any update on this (that works for non-dev users)?
Bumping this as this issue still has not been fixed as of the latest stable or beta release, and it seems to be a problem that if resolved would allow for easy replication among other OBS panels and display elements on macOS
Happy to see that there is a workaround but would've never guessed that compiling (parts of) OBS to fix copy&paste will land on my todo list.
If possible I'd suggest documenting this lack of feature parity between different OS versions somewhere easier to find, especially for normal users. It took me way too long to discover why I'm failing to edit the Twitch stream information on my Macbook.
OBS 31.0.3 (64 bit), macOS Sequoia 15.5 (24F74)
Is this fixed? I ran into this days ago. Not sure how it blocks system level keyboard shortcuts on macOS but accessibility-wise it's not great.