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

ScriptError "TypeError Property 'text' Exit code 4" #2520

Closed
iG8R opened this issue Oct 27, 2023 · 16 comments
Closed

ScriptError "TypeError Property 'text' Exit code 4" #2520

iG8R opened this issue Oct 27, 2023 · 16 comments
Labels

Comments

@iG8R
Copy link

iG8R commented Oct 27, 2023

Describe the bug
When I try to execute script the error " TypeError: Property 'text' Exit code: 4" appears.

To Reproduce
Steps to reproduce the behavior:

  1. Apply the following script to a clip that contains a note with a URL.
[Command]
Command="
    copyq:
    var url = input().text()
    if ( open(url) )
      popup('Opening URL', url)
    else
      popup('Failed to open URL', url)"
HideWindow=true
Icon=\xf0ac
InMenu=true
Input=application/x-copyq-item-notes
Name=Open in &Browser
  1. See the aforementioned error.

Expected behavior
Opening the URL located in the clip note in the browser.

Screenshots

CopyQ-Open-in-Browser-Video_2023-10-27_073333.webm

Version, OS and Environment

  • CopyQ 7.1.0
  • OS: Microsoft Windows [Version 10.0.19045.2673] 64bit
  • Browser: Firefox 119.0 64bit
  • Browser: Chrome 118.0.5993.90 (Official Build) (64-bit)
  • Browser: Edge 118.0.2088.69 (Official build) (64-bit)
@iG8R iG8R added the bug label Oct 27, 2023
@iG8R
Copy link
Author

iG8R commented Oct 28, 2023

Changed
var url = input().text()
to
var url = input()

The error has also changed:
Warning [2023-10-29 01:07:17.030] <Server-18540>: [default] QtWarning: ShellExecute 'https://github.com/hluk/CopyQ/issues/2084%00' failed (error 2).

But if I explicitly insert the URL into the code, like this
var url = 'https://github.com/hluk/CopyQ/issues/2084'
then this URL opens in the browser without any problems.

@iG8R
Copy link
Author

iG8R commented Oct 29, 2023

Through trial and error, it was found that if the link is opened in this format
var url = 'https://github.com/hluk/CopyQ/issues/2084'
then everything works as it should, i.e. the browser page opens with this link.

But in this case
var url = 'https://github.com/hluk/CopyQ/issues/2084%00'
gives an error
Warning [2023-10-29 03:00:10.915] <Server-18540>: [default] QtWarning: ShellExecute 'https://github.com/hluk/CopyQ/issues/2084%00' failed (error 2).

So, in some incomprehensible way, %00 is added to the link at the end.

@iG8R
Copy link
Author

iG8R commented Oct 30, 2023

@hluk
Hi.
I want to clarify the situation from the very beginning.
There are 2 scripts taken from the following topic "Bug or feature ?" #1100

  1. Add URL label & Add URL label (Edge) Bug or feature ? #1100 (comment)
Add URL label & Add URL label (Edge) (click to open)
[Commands]
1\Automatic=true
1\Command="
    copyq:
    removeData('text/x-moz-url-priv')
    setData(mimeItemNotes, input())"
1\Icon=\xf15b
1\Input=text/x-moz-url-priv
1\Name=Add URL label
2\Automatic=true
2\Command="
    copyq:
    removeData('application/x-qt-windows-mime;value=\"msSourceUrl\"')
    setData(mimeItemNotes, input())"
2\Icon=\xf15b
2\Input="application/x-qt-windows-mime;value=\"msSourceUrl\""
2\Name=Add URL label (Edge)
size=2
  1. Open in &Browser Bug or feature ? #1100 (comment)
Open in &Browser (click to open)
[Command]
Command="
    copyq:
    var url = input().text()
    if ( open(url) )
      popup('Opening URL', url)
    else
      popup('Failed to open URL', url)"
HideWindow=true
Icon=\xf0ac
InMenu=true
Input=application/x-copyq-item-notes
Name=Open in &Browser

So, for some unknown reason, the script Add URL label & Add URL label (Edge) adds %00 at the end of the URL when adding it to the mimeItemNotes of the clip.
I found a solution - before saving to mimeItemNotes, use the chop(1) command to remove this last character before saving.

[Command]
Name=Add URL label
Command="
    copyq:
    removeData('text/x-moz-url-priv')
    var url = input()
    url.chop(1)
    setData(mimeItemNotes, url)"
Input=text/x-moz-url-priv
Automatic=true
Icon=\xf15b

But most likely there is some bug in CopyQ, which is causing such behavior. Therefore, it would be better if the error itself is fixed, rather than using such workarounds.

@hluk
Copy link
Owner

hluk commented Oct 31, 2023

Changed
var url = input().text()
to
var url = input()

There is no attribute text for ByteArray (the return type of input()). Your fixed code looks OK.

But in this case var url = 'https://github.com/hluk/CopyQ/issues/2084%00' gives an error Warning [2023-10-29 03:00:10.915] <Server-18540>: [default] QtWarning: ShellExecute 'https://github.com/hluk/CopyQ/issues/2084%00' failed (error 2).

So, in some incomprehensible way, %00 is added to the link at the end.

It looks like the original data contains trailing null character. I can reproduce this from shell:

# Web browser opens: https://github.com/hluk/CopyQ/issues/2520%00printf "%s\0" "https://github.com/hluk/CopyQ/issues/2520" | copyq 'open(input())'
true

# ByteArray with null character converted to string still contains the null (bellow is the hexadecimal representation of the string)printf "HELLO\0" | copyq 'str(input())' | xxd
00000000: 4845 4c4c 4f00 0a                        HELLO..

# Here is the input without nullprintf "HELLO" | copyq 'str(input())' | xxd
00000000: 4845 4c4c 4f0a                           HELLO.

It seems that the following works well, provided the input is in Latin1 encoding (the standard ISO 8859-1 character set):

var url = input().toLatin1String()

The question is why the item note contains the null character. I assume that the clipboard content might have been misinterpreted by CopyQ or the underlying Qt framework (which handles most of the clipboard data transformations/representation).

Which app did you copy the URL from?

@iG8R
Copy link
Author

iG8R commented Oct 31, 2023

I didn't copy the URLs themselves, I copied the texts from the aforementioned Firefox, Edge and Chrome and after that "Add URL label & Add URL label (Edge)" did all the rest of the work on adding URLs to the "Note" fields of the clips.

@hluk
Copy link
Owner

hluk commented Oct 31, 2023

I cannot reproduce the trailing null character when copying from Firefox. I think this could be a problem in the source application. Probably not worth adding a workaround in CopyQ for this.

@hluk hluk closed this as completed Oct 31, 2023
@hluk
Copy link
Owner

hluk commented Oct 31, 2023

Let me know if you can reproduce it (and how) when copying from the source app. I would prefer to have a proper fix in CopyQ if that will be possible.

@iG8R
Copy link
Author

iG8R commented Oct 31, 2023

Here is the most common process of copying text in Firefox:

CopyQ-Copying-NULL-Video_2023-10-31_162525.webm

@hluk
Copy link
Owner

hluk commented Oct 31, 2023

Oh, the item notes with URL are created automatically with a command. Can you share the command code here with "Copy Selected" button?

BTW, thanks for posting the screencasts - very useful!

@iG8R
Copy link
Author

iG8R commented Oct 31, 2023

Under the "Copy Selected" button, do you mean this one?

image

This is an external application - SnipDo, an analogue of Popclip on MacOS.

All the work is done by CopyQ using the two scripts I mentioned above #2520 (comment)

BTW, thanks for posting the screencasts - very useful!

You are welcome, and thank you for your work, and I, as a user, just try to convey information about the problem as clearly as possible so as not to force you to develop telepathy as well.

@hluk
Copy link
Owner

hluk commented Nov 1, 2023

I mean this process: https://copyq.readthedocs.io/en/latest/faq.html#how-to-load-shared-commands-and-share-them

To share your commands, you can select the commands from command list in “Commands” dialog and press “Copy Selected” button (or just hit Ctrl+C).

And paste the command into a comment in this issue.

@iG8R
Copy link
Author

iG8R commented Nov 1, 2023

Oh, I see.
This is what works in Firefox, but not in Edge and Chrome.

[Command]
Name=Add URL label
Command="
    copyq:
    removeData('text/x-moz-url-priv')
    var url = input()
    url.chop(1)
    setData(mimeItemNotes, url)"
Input=text/x-moz-url-priv
Automatic=true
Icon=\xf15b

This one, which supposed to work in Edge and Chrome, doesn't work in either of them.

[Command]
Name=Add URL label (Edge)
Command="
    copyq:
    removeData('application/x-qt-windows-mime;value=\"msSourceUrl\"')
    setData(mimeItemNotes, input())"
Input="application/x-qt-windows-mime;value=\"msSourceUrl\""
Automatic=true
Icon=\xf15b

PS. Please take a look at my screencast on the more troubling issue of not being able to copy images from browsers.
#2084 (comment)

@hluk
Copy link
Owner

hluk commented Nov 1, 2023

I tested it on Linux with Firefox 118.0.2 and there is no trailing null character in the URL:

❯ copyq clipboard text/x-moz-url-priv|xxd
00000000: 6874 7470 733a 2f2f 6769 7468 7562 2e63  https://github.c
00000010: 6f6d 2f68 6c75 6b2f 436f 7079 512f 6973  om/hluk/CopyQ/is
00000020: 7375 6573 2f32 3532 30                   sues/2520

I also checked Chromium but it does not seem to provide the URL in clipboard. You can check the formats by copying from the web browser and opening Clipboard Content dialog in CopyQ (Ctrl+Shift+C).

@iG8R
Copy link
Author

iG8R commented Nov 1, 2023

It seems, this command doesn't work in Windows.

image

Regarding trailing NULL in URLs

image

As you can see, the trailing NULL character appears before the URL is recorded into Note. (application/x-copyq-item-notes)

PS. I apologize, but I didn't quite understand what was meant by
You can check the formats by copying from the web browser and opening Clipboard Content dialog in CopyQ (Ctrl+Shift+C).
I have the following information displayed in this window.

CopyQ-Clipboard-Contnet-formats-Video_2023-11-01_182429.webm

@hluk
Copy link
Owner

hluk commented Nov 2, 2023

It seems, this command doesn't work in Windows.

The console output on Windows does not work for GUI apps unfortunately (#349).

You can use the Action dialog (F5 shortcut) in CopyQ instead with "Store standard output" set to "text/plain" to store the command output to new item.

PS. I apologize, but I didn't quite understand what was meant by You can check the formats by copying from the web browser and opening Clipboard Content dialog in CopyQ (Ctrl+Shift+C).

More specifically: Use the Clipboard Content to figure out the format name containing URL for the current system clipboard content visible by CopyQ. It should list text/x-moz-url-priv for stuff copied from web pages in Firefox.

@iG8R
Copy link
Author

iG8R commented Nov 3, 2023

CopyQ-Notes-issue-Video_2023-11-03_014635_part1.webm
CopyQ-Notes-issue-Video_2023-11-03_014635_part2.webm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants