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 site copy/cut/paste/text selection restrictions for password/input fields #974

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mallexxx
Copy link
Contributor

export default class CopyPasteMenuSelectionOverride extends ContentFeature {
init () {
try {
(() => {
Copy link
Contributor

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 = `
(() => {
Copy link
Contributor

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.

Copy link
Contributor Author

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".

Copy link
Contributor

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') {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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];
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the console log.

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