How to properly use and operate !USERAGENT ?

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
rapieragnay
Posts: 11
Joined: Sun Jan 24, 2021 11:06 am

How to properly use and operate !USERAGENT ?

Post by rapieragnay » Tue Mar 02, 2021 8:09 pm

Hi all,

My config: iMacros 8.9.7 + FF 52 + Win 7

I am using iMacros Scripting Interface, and I created a function that contains GOTO URL = url to browse the web.

Code: Select all

chrome = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';
function goto(url) {
        code = 'SET !USERAGENT "'+ chrome +'"'+'\n';
        code+= "URL GOTO="+url+"\n";
        iimPlayCode(code);    
}
I defined !USERAGENT before URL GOTO, but this is ignored: the page always displays my real useragent (Firefox).

Do you have a tip? Thanks
chivracq
Posts: 9756
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to properly use and operate !USERAGENT ?

Post by chivracq » Tue Mar 02, 2021 10:18 pm

rapieragnay wrote:
Tue Mar 02, 2021 8:09 pm
Hi all,

My config: iMacros 8.9.7 + FF 52 + Win 7

I am using iMacros Scripting Interface, and I created a function that contains GOTO URL = url to browse the web.

Code: Select all

chrome = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';
function goto(url) {
        code = 'SET !USERAGENT "'+ chrome +'"'+'\n';
        code+= "URL GOTO="+url+"\n";
        iimPlayCode(code);    
}
I defined !USERAGENT before URL GOTO, but this is ignored: the page always displays my real useragent (Firefox).

Do you have a tip? Thanks

Hum..., works fine for me from some "quick" Test in pure '.iim' using the following Script:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX

SET !USERAGENT "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"

URL GOTO=https://demo.imacros.net/UserAgent.aspx
PAUSE
(Tested on [iMacros for FF v8.9.7, FF v55.0.3, Win10_x64] + [iMacros for FF v8.8.2, PM v26.3.3, Win10_x64].)

Notice the 'PAUSE' after loading the iMacros UA/Browser Detection Test Page, after/during the 'PAUSE', a manual Refresh of the Page will keep yielding CR83 as my UA, and once I resume the Script with 'Continue' to let it finish "naturally", then my UA gets back to FF55:

Code: Select all

Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0
And this is the "normal" (= "documented") Behaviour:
Firefox: The user agent string is reset after each invocation of your macro or script.
>

BUT...!, and this is maybe the Behaviour that you would like... :idea: , even if it feels a bit like a Bug to me..., if I abort the Script with 'Stop' during the 'PAUSE', then CR83 becomes my "new" Default UA, and I need to reset my UA with "" (I didn't test) or to restart FF (I tested) if I want to be able to go back to FF55 as my Default UA... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
rapieragnay
Posts: 11
Joined: Sun Jan 24, 2021 11:06 am

Re: How to properly use and operate !USERAGENT ?

Post by rapieragnay » Wed Mar 03, 2021 4:34 am

The code below describes the issue I'm facing in more detail

The first action gives me the user-agent what I need. (CR83)
The second action (click a button on the page) brings up my default user-agent. (FF52)

What action do I need to keep the new user-agent for all actions performed on that tab/window ?

Code: Select all

    chrome = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';
    function goto(url) {
            code = 'SET !USERAGENT "'+ chrome +'"'+'\n';
            code+= "URL GOTO="+url+"\n";
            iimPlayCode(code);    
    }
    url = 'https://developers.whatismybrowser.com';
    goto(url);
    code = 'WAIT SECONDS=10'+'\n';
    code += 'TAG POS=1 TYPE=INPUT:SUBMIT ATTR=CLASS:button<SP>button-filled-blue<SP>button-next-to-input'+'\n';
    iimPlayCode(code);
techimac
Posts: 397
Joined: Fri Feb 20, 2015 9:27 pm

Re: How to properly use and operate !USERAGENT ?

Post by techimac » Wed Mar 03, 2021 7:30 am

Code: Select all

var code = "";
code += "CODE:" + "\n";
code += "SET !USERAGENT {{ua}}" + "\n";
code += "URL GOTO={{url}}" + "\n";
code += "WAIT SECONDS=10" + "\n";
code += "TAG POS=1 TYPE=INPUT:SUBMIT ATTR=CLASS:button<SP>button-filled-blue<SP>button-next-to-input" + "\n";

iimSet("ua",'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36')
iimSet("url",'https://developers.whatismybrowser.com')
iimPlay(code)
Available for custom iim, javascript iMacros scripts
techimac
Posts: 397
Joined: Fri Feb 20, 2015 9:27 pm

Re: How to properly use and operate !USERAGENT ?

Post by techimac » Wed Mar 03, 2021 7:32 am

rapieragnay wrote:
Wed Mar 03, 2021 4:34 am
The code below describes the issue I'm facing in more detail

The first action gives me the user-agent what I need. (CR83)
The second action (click a button on the page) brings up my default user-agent. (FF52)

What action do I need to keep the new user-agent for all actions performed on that tab/window ?

Code: Select all

    chrome = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';
    function goto(url) {
            code = 'SET !USERAGENT "'+ chrome +'"'+'\n';
            code+= "URL GOTO="+url+"\n";
            iimPlayCode(code);    
    }
    url = 'https://developers.whatismybrowser.com';
    goto(url);
    code = 'WAIT SECONDS=10'+'\n';
    code += 'TAG POS=1 TYPE=INPUT:SUBMIT ATTR=CLASS:button<SP>button-filled-blue<SP>button-next-to-input'+'\n';
    iimPlayCode(code);

Code: Select all

code = 'SET !USERAGENT "'+ chrome +'"'+'\n';
    code += 'WAIT SECONDS=10'+'\n';
    code += 'TAG POS=1 TYPE=INPUT:SUBMIT ATTR=CLASS:button<SP>button-filled-blue<SP>button-next-to-input'+'\n';
    iimPlayCode(code);
Available for custom iim, javascript iMacros scripts
chivracq
Posts: 9756
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to properly use and operate !USERAGENT ?

Post by chivracq » Wed Mar 03, 2021 10:37 am

rapieragnay wrote:
Wed Mar 03, 2021 4:34 am
The code below describes the issue I'm facing in more detail

The first action gives me the user-agent what I need. (CR83)
The second action (click a button on the page) brings up my default user-agent. (FF52)

What action do I need to keep the new user-agent for all actions performed on that tab/window ?

Code: Select all

    chrome = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';
    function goto(url) {
            code = 'SET !USERAGENT "'+ chrome +'"'+'\n';
            code+= "URL GOTO="+url+"\n";
            iimPlayCode(code);    
    }
    url = 'https://developers.whatismybrowser.com';
    goto(url);
    code = 'WAIT SECONDS=10'+'\n';
    code += 'TAG POS=1 TYPE=INPUT:SUBMIT ATTR=CLASS:button<SP>button-filled-blue<SP>button-next-to-input'+'\n';
    iimPlayCode(code);

Yep OK, but "again", this is "normal" (= By Design) Behaviour as you've split the Logic of your Script into 2 separate 'iimPlayCode()' Calls, where (By Design) all Vars and Built-in Vars get reset at the end of an 'iimPlayCode()' Call.

You would get the same Behaviour with any '!TIMEOUT_xxx' Vars, any '!VAR[n]' Vars or User-defined Vars (+ 'iimSet()' that you would need to call also each time), or even with '!ERRORIGNORE' for example...
The only Exception that I know of is with the 'FILTER' Command which doesn't get reset, and this is actually a "slightly" annoying Bug that I have reported many times already... :(

=> In order to get your UA "sticky" to "CR83", you then need to group all Actions together in one same on-the-fly Macro executed by one same 'iimPlayCode()' Call, ... or to repeat the "SET !USERAGENT xxx" Statement in all Sub-Macros like @techimac posted in his 2 Scripts... :idea:

>>>

Or make use/misuse :shock: of the mini-Bug I noticed and described in my previous Post, by first running and aborting manually some mini-Macro, then your UA will remain "sticky" for any new Scripts you'll be running afterwards... :idea:

And/or maybe worth testing, it could be that you also get the same Behaviour/Func if you call that "mini-Macro" from your "main-Macro" and add some "fake" 'TAG' Statement (that won't be found) that will cause that Sub-Macro to abort "naturally", then it's possible that "maybe" the UA doesn't get reset, but I don't know, you would need to test/try... Same also with 'MacroError()' maybe... :idea:

I know of a "Bug" with the '!EXTRACT' Var which doesn't always get reset and where in some "Circumstances", it is possible to still retrieve the Content of '!EXTRACT' from some previously run Macro..., so maybe in some "edgy" Conditions with 'PAUSE'/'Abort'/'RuntimeError'/'MacroError()'/etc..., you'll be able to create some "unexpected" Behaviour that can always be used as a "Workaround" for some Scenario, ah-ah...! :twisted:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
rapieragnay
Posts: 11
Joined: Sun Jan 24, 2021 11:06 am

Re: How to properly use and operate !USERAGENT ?

Post by rapieragnay » Wed Mar 03, 2021 12:05 pm

I am going to choose this solution :
=> In order to get your UA "sticky" to "CR83", you then need to repeat the "SET !USERAGENT xxx" Statement in all Sub-Macros

Thank you.
chivracq
Posts: 9756
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to properly use and operate !USERAGENT ?

Post by chivracq » Wed Mar 03, 2021 12:21 pm

rapieragnay wrote:
Wed Mar 03, 2021 12:05 pm
I am going to choose this solution :
=> In order to get your UA "sticky" to "CR83", you then need to repeat the "SET !USERAGENT xxx" Statement in all Sub-Macros

Thank you.

Alright..., yep..., good-good... And Thanks for the Feedback/Follow-up... :D

>>>

And "for myself", I will actually start using the "mini-Bug" about the UA becoming "sticky" after aborting a mini-'.iim' Macro... :P

I was using "until now" some FF Add-on called "User Agent Switcher", but the Method with iMacros will actually be much easier with just 3 easy Clicks while I had to navigate through several DDLB's and Sub-Menus in PM/FF with 'User Agent Switcher', + updating the UA-Database with new UA's was always quite a bit of a hassle, this will be easier with iMacros Thanks to this mini-Bug, ah-ah...! 8) :twisted:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply