-
Notifications
You must be signed in to change notification settings - Fork 21
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 site copy/cut/paste/text selection restrictions for password/input fields #974
base: main
Are you sure you want to change the base?
Conversation
export default class CopyPasteMenuSelectionOverride extends ContentFeature { | ||
init () { | ||
try { | ||
(() => { |
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 don't think you need this.
// from client content world script handling `contextmenu` events. | ||
var alertSuppressionScript = document.createElement('script'); | ||
alertSuppressionScript.textContent = ` | ||
(() => { |
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 don't think this needs to be an injected script and instead just a method.
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 reason behind this is the ContentScopeScript
being injected as a defaultClient
scope script and the alert
method is called by the document from the page
scope, so they don‘t intersect, this hack is here to pass shouldSuppressAlert
flag between the page
and defaultClient
scope and handle the alert
call in the page
scope. I‘m open for suggestions on how to handle this in "the right way".
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.
Ah because in "src/features.js" you put it in apple-isolated, put it in the normal.
|
||
const selectionColor = window.getComputedStyle(node, '::selection').backgroundColor; | ||
// if text node selection color is set to `transparent` (0,0,0,0) or is not set explicitly - set it to default (`highlight`) | ||
if (selectionColor === 'rgba(0, 0, 0, 0)' || selectionColor === 'transparent') { |
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.
There's a bunch of other values here that are could cause it not to show. Like visibility:hidden, also does #00000000 appear in computed styles or is it translated to rgba?
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.
It seems like the default in Chrome is rgba(0, 0, 0, 0)
, I'm not sure how the style applies but we should probably not apply in default case.
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.
yes, the default is detected rgba(0, 0, 0, 0)
(i.e. not explicitly defined), but may also be used from the client side to hide selection.
but we should probably not apply in default case
I agree, but there seems no way to distinguish the "not defined" case and an explicit rgba(0, 0, 0, 0)
. The overridden style sets selection background color to highlight
which is a default browser selection color, so in case it‘s not explicitly defined – the selection colors remains the same.
`; | ||
styleElement.textContent = cssRules; | ||
|
||
document.head.appendChild(styleElement); |
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.
It would be better to add these styles inline rather than injecting DOM nodes.
lastContextMenuEventX = e.clientX; | ||
lastContextMenuEventY = e.clientY; | ||
// prevent websites displaying alerts on right click | ||
const suppressAlertFlagElement = document.getElementsByTagName("_ddg-suppress-alert-flag")[0]; |
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.
It's not clear why you need a DOM node to store this variable at all.
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.
to pass value between page
and defaultClient
scopes, see the comment above.
// prevent websites displaying alerts on right click | ||
window.alert = function(msg) { | ||
if (shouldSuppressAlert()) { | ||
console.log("suppressed alert on contextmenu: " + msg); |
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.
Remove the console log.
Task URL: https://app.asana.com/0/42792087274227/1201373420681703/f
Steps to validate:
copyPasteMenuSelectionOverride
in the config