[FIX] web: fix copying to clipboard no longer working
Since commit (1), the write/writeText were no longer correctly called, because the browser native functions couldn't be called. Sometimes, it raised the "Illegal invocation..." error, or could have an unexpected behavior, preventing the value to be copied in the clipboard, which made the button pointless. No additional test was added, since it is difficult to test the clipboard API programmatically, and the current test coverage is all that we can do, without using the real clipboard object. (1): 9cdcd1c1f7219030386d2c90205ea083eb835a13 closes odoo/odoo#112843 X-original-commit: 767922d43334a6cbccdb4be64f207813240fd314 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -28,15 +28,16 @@ export class CopyButton extends Component {
|
||||
// any kind of content can be copied into the clipboard using
|
||||
// the appropriate native methods
|
||||
if (typeof this.props.content === "string" || this.props.content instanceof String) {
|
||||
write = browser.navigator.clipboard.writeText;
|
||||
write = (value) => browser.navigator.clipboard.writeText(value);
|
||||
} else {
|
||||
write = browser.navigator.clipboard.write;
|
||||
write = (value) => browser.navigator.clipboard.write(value);
|
||||
}
|
||||
write(this.props.content).then(() => {
|
||||
this.showTooltip();
|
||||
}).catch((error) => {
|
||||
browser.console.warn("This browser doesn't grant access to copy to clipboard");
|
||||
});
|
||||
try {
|
||||
await write(this.props.content);
|
||||
} catch(error) {
|
||||
return browser.console.warn(error);
|
||||
}
|
||||
this.showTooltip();
|
||||
}
|
||||
}
|
||||
CopyButton.template = "web.CopyButton";
|
||||
|
||||
Reference in New Issue
Block a user