Page navigation using Playwright with JAVA running under AWS VPN connection not working - vpn

I'm working under AWS VPN connection and when I try simple page navigation to site that is under AWS VPN connection using playwright JAVA code, I'm getting timeout and the page navigation is not opening the site.
If I do it manually using Chrome browser under active AWS VPN connection the site is opening. all is good.
I wonder if the reason is that PW is launches the browser in Incognito mode , but I also tried using non Incognito mode but still under AWS VPN the site is not opening ? strange
do you have any idea how to solve this?
see this is my simple code that is running under VPN
Playwright playwright = Playwright.create();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int)screenSize.getWidth();
int height = (int)screenSize.getHeight();
Path userDataDir = Paths.get(System.getenv("LOCALAPPDATA"),"\\Google\\Chrome\\User Data", "");
BrowserType.LaunchPersistentContextOptions browserOptions = new BrowserType.LaunchPersistentContextOptions();
browserOptions.setHeadless(false);
browserOptions.setChannel("chrome");
browserOptions.setTimeout(120000);
browserOptions.setViewportSize(width,height);
BrowserContext browserContext = playwright.chromium().
launchPersistentContext(userDataDir,browserOptions);
Page page = browserContext.newPage();
page.setDefaultTimeout(120000);
page.setDefaultNavigationTimeout(120000);
page.navigate(url); // in this line the browser is stuck and wait and wait ...
page.locator("input#username").fill(username);
page.locator("input#password").fill(password);
page.locator("button[type='submit']").click();

Related

Xamarin Android project cannot connect to localhost API

I have been working on this problem for quite some time. I've read the many similar posts and their solutions don't help me (many posts are old and stale). I have a new Xamarin project and a localhost API that I am testing to. Initially I installed our production API locally and it doesn't connect. So I created a smaller test API and have had varying results in connecting. Xamarin Android will not connect with a "Failed to connect to localhost:XXXXX" message. I built a WPF project and get the same results. However I can connect to outside public API's (github) with both. I can connect to my localhost with a Windows forms desktop app and successfully get & post. Postman and httprepl both connect locally and successfully get & post. A couple of the other things the other posts suggested are 1) Client handler to ignore SSL - doesn't work, 2) Use the emulator's browser to connect to localhost - cannot connect. (this might be exposing where the problem really is but not sure).
Also The debugger seems to be behaving oddly. When the debugger gets to the HttpResponseMessageresponse.... line it rarely makes it to the next line so I cannot inspect the statuscode. The block I have below is in a try/catch and rarely makes it to the catch if the connection truly fails. Sometimes it will be caught at the catch and that's how I get the "failed to connect" message. Another developer here has run the project on his computer and gets the same results/errors on his computer.
HttpResponseMessage response = await client.SendAsync(request);
var Statuscode = response.StatusCode;
if (response.IsSuccessStatusCode)
{
var jsonbody = response.Content.ReadAsStringAsync().Result;
var ResponseBody = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
}
else
{
string oops = "Nothing";
}
I seem to be running out of options and am looking for any advice.
Thanks in advance.

How to start a new process in an asp.net web application

The default browser on our web servers is IE. We have a requirement to launch an instance of Chrome on a button click on one of our web apps.
I have written an asp.net test app to try to achieve the above. In the test app I start a process on a button click on the server side to launch Chrome, but the Chrome window does not appear. The process seems to start fine as I get the the process ID and HasExited property is false. However, nothing comes up on screen and I don't seem to be able to find the process in the list of processes.
I know that in a web app, a process starts in the context of the asp.net worker process and that it does not have access to the desktop and has restricted permissions. So I gave the IIS Admin Service process permission to interact with desktop on my local machine (via Processes window). Also, in the code I tried starting the process using my own user account which has admin access to the local machine but still could not get the Chrome window to appear on screen.
My server side code is as follows:
var psi = new ProcessStartInfo
{
FileName = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
Arguments = "http://www.msn.com",
CreateNoWindow = false,
UseShellExecute = true
UserName = "username",
Password = "secure password",
Domain = "domain"
};
var process = new Process
{
StartInfo = psi
};
var result = process.Start(); // result is true
int processId = process.Id; // processId is valid
I would appreciate your help.

RGoogleAnalytics Auth function wont open the browser for "Request for Permission"

I'm using the RGoogleAnalytics package in a remote Desktop (in a different country), i'm not using my local machine since Google blocks my local machine due to restrictions.
In my local machine, when i run the 'Auth' command:
token <- Auth(client.id = "XXXXXXXXXXXXXXXXXXXXXXX",
client.secret = "YYYYYYYYYYY")
the browser automatically opens a new tab ("Request for permission") in the browser for me to accept (natural part of authentication) - This is what should happen, though when i'm doing it through my remote machine (where i'm logged into the GA account, how it should work), My R console just gets stuck with the following command, without automatically opening a new request for permission tab in the browser:
token <- Auth(client.id = "XXXXXXXXXXXXXXXXXXXXXXX",
client.secret = "YYYYYYYYYYY")
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Has anyone ran into this issue at the past? I've actually used this package quit a lot and never ran into this weird issue
Thanks in advance for any help on this one :)
I solved this by launching a browser remotely :
ssh user#server -Y firefox
...and launching Rstudio as if it was on localhost.
Just make sure you have a port for Google API authentication response (likely 1410) open for TCP

PushSharp GCM "Authentication Failed"

I have been using PushSharp for Apple notifications for some time in both a web service and a windows service without any issues.
On adding the code for Google GCM, it works perfectly fine on my web service and a console app I converted the service to, but it fails miserably in the windows service even when run on the same server (Amazon EC2 Instance)
The following code gives an "Authentication Failed" error for the GCM notification and has no error for the Apple notification. However, If I run the same code in my web service or a console app on the same server, it works fine.
Dim push As PushBroker = New PushBroker
Try
AddHandler push.OnNotificationSent, AddressOf NotificationSent
AddHandler push.OnNotificationFailed, AddressOf NotificationFailed
Dim appleCert = File.ReadAllBytes("FILENAME")
push.RegisterAppleService(New ApplePushChannelSettings(False, appleCert, "PASSWORD"))
push.RegisterGcmService(New GcmPushChannelSettings("API_KEY"))
push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("ANDROID-TOKEN").WithJson("{""alert"":""Hello World!"",""badge"":1,""sound"":""sound.caf""}"))
push.QueueNotification(New AppleNotification().ForDeviceToken("IOS-TOKEN").WithContentAvailable(1))
Catch ex As Exception
End Try
If I remove the line:
push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("ANDROID-TOKEN").WithJson("{""alert"":""Hello World!"",""badge"":1,""sound"":""sound.caf""}"))
it works perfectly on both the windows service and the web service.
Can anyone see what I am doing wrong? It is not a firewall issue. I turned off the firewall and it still didn't work. I had a lot of other code and have distilled it down to the above code to make sure there were no hidden issues.
EDIT. I set up a console app copying the code from the windows service and used the Browser API Key instead of the Server API key.
This works perfectly on both my local machine and the server machine. However the windows service still gets the same error whichever API key I use.
UPDATE: Although the Windows Service is receiving the error, it does actually send two notifications and then no more. If I stop the service and start it again, I get another two notifications even though the notification error is still being returned.
I'm really stuck. I can just continuously run the console app for now, but its hardly perfect. Any help would be gratefully received.
I had a similar issue - everything worked fine in Visual Studio but on the production server AndroidGcm authentication failed.
I figured it was something to do with the IP list in the 'Key for server applications' so I tried regenerating one with the IP address of my server. This didn't work.
Eventually in response to one of the above comments and another thread elsewhere I logged onto the Google Play Developer Console from the server and created a new key, without specifying any IP addresses.
Using this key then fixed my problem

Why won't OAuth work on web server?

I have an ASP.Net web application running on Windows Server 2012, and need to make calls to social networking sites using oauth to generate some of the page content. Everything works on my development machine, but I can't even get a single response back ("unable to connect to the remote server" error).
I disabled the firewall to test that. No luck. I created a console application to test it that way. A simple HttpWebRequest will get the html for any page I throw at it, but not any oauth request. I've used different libraries to try to achieve this, including Linq2Twitter, Spring.Social, and HigLabo. All work locally, but not on the server. I've found nothing useful in the server event log.
Can anyone give me some clues what might be happening?
EDIT: Here's some code I'm using with the HigLabo library to try to retrieve the user timeline.
using HigLabo.Net.Twitter;
var cl = new TwitterClient(consumerKey, consumerSecret, accessToken, accessTokenSecret);
var rr = cl.GetHomeTimeline();
foreach (var r in rr)
{
//Console.WriteLine(r.CreatedAt + ":" + r.Text);
}
I'm aware that accessToken & accessTokenSecret aren't/shouldn't be necessary for a simple timeline read, but this is just to make sure it works first.
This turned out to be a firewall issue, as had been suspected. But not the server firewall. This was a problem with the ISP. They had an internal firewall that was blocking all traffic to/from the social network sites. They were able to resolve it quickly with a phonecall, but it was not a coding or configuration error on my part.

Resources