This is a migrated thread and some comments may be shown as answers.

Utilities.CopyToClipboard(); does not work

4 Answers 33 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 06 Mar 2019, 11:15 AM

I wrote my simple fiddler script to automatically copy to clipboard but always getting error

"The current wire must be set to STA mode (Single Thread Apartment) before calling to OLE. Make sure STAThreadAttribute is selected in the Main function."

My workaround is to show dialog box and CTRL+C from there

How do i fix it?

4 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 08 Mar 2019, 06:33 AM
Hi,

Which version of Fiddler are you using? Also would it be possible to provide me with the code snippet which caused the problem?

Regards,
Alexander
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
David
Top achievements
Rank 1
answered on 11 Mar 2019, 09:26 PM

I'm using version 5.0.20182.28034

Here is the code snippet

I'm quite new to javascript. I just needed few lines to get it done hehe

class Handlers
{
    static function OnBeforeRequest(oSession: Session) 
    { //
        if(oSession.uriContains("string here"))
        {
            Utilities.CopyToClipboard("string here");
        }     
    } 
}

0
Simeon
Telerik team
answered on 26 Mar 2019, 10:28 AM
Hello David,

Thank you for reporting this issue. I have logged and it will be fixed in a future version of Fiddler.

Until then, I would like to propose you a work-around. Using the C# FiddlerScript language, which you could set from Tools\Options, Scripting tab and select the C# from the Language dropdown.
Then you could call the CopyToClipboard method in an STA thread like this:
using System.Threading;
//
 
namespace Fiddler
{
    public static class Handlers
    { //
        public static void OnBeforeRequest(Session oSession)
        { //
            if (oSession.uriContains("string here"))
            {
                Thread t = new Thread(() => Utilities.CopyToClipboard("string here"));
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
            }
        }
    }
}


Regards,
Simeon
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
David
Top achievements
Rank 1
answered on 03 Apr 2019, 10:34 AM

Thanks very much

I better wait for update cause I'm more familar with JS and its regex system than C#

Tags
Fiddler Classic
Asked by
David
Top achievements
Rank 1
Answers by
Alexander
Telerik team
David
Top achievements
Rank 1
Simeon
Telerik team
Share this question
or