Get website html source with PhantomJS in Azure Web Job - javascript

I am using PhantomJS and Selenium WebDriver to download the page source from a website with the following code:
var driverService = PhantomJSDriverService.CreateDefaultService();
//error occurs here
var driver = new PhantomJSDriver(driverService);
driver.Navigate().GoToUrl(url);
htmlCode = driver.PageSource;
driver.Quit();
Everything works fine in my local environment but gives the following error in an Azure Web Job or Azure Website:
Unable to connect to the remote server --->
System.Net.Sockets.SocketException: An attempt was made to access a
socket in a way forbidden by its access permissions 127.0.0.1:50388
I get an equal error message when running Selenium with Firefox as an Azure Web Job or Azure Website. I already activated "Web Sockets" in Azure Web App configuration dashboard. But the error still occurs.
My goal is to get the rendered (javascript and ajax) page source of a website inside a Azure Web Job.

I was getting a similar error on my task and it was because I was hitting the cpu limit for the azure plan for my instance. I upgraded from 'free' to 'shared' and it still did not work. It worked after upgrading to 'basic'. Maybe that will help...
This was the link that helped me: https://social.msdn.microsoft.com/Forums/vstudio/en-US/1eb5e0fb-79b9-4f55-8345-7f50053c13c1/webjobs-no-consistnet-behavior?forum=windowsazurewebsitespreview

Related

How to debug apps on an AVD via a browser

I am new to coding web apps on Android, and I don't know how to debug apps running in an emulator via a browser. This page: Remote debug Android apps suggests that to debug apps remotely, you need to connect your Android device via USB to the remote system. I am confused as to how to achieve this with an AVD. Has anyone got any answers??
Edit:
I actually posted this question as I was getting "HTTP/1.1 404 not found" whenever I run chrome://inspect/#devices for an AVD, but I wasn't getting same error whenever I run it through my Android device.
However, currently I have found an SO question addressing this issue

How To Run a Flutter Web Application Offline?

I got a problematic assignment from my employers.
I was given the task of developing simple software that will run strictly on Google Chrome,
without attempting to connect to the web (Security reasons).
I know flutter development and I feel comfortable with the sdk.
How should I develop a web app that can be deployed using a usb stick?
Looks like PWA can be an option, but the documentation is lacking in detail.
The system does not have the ability to run a local web server.
The Flutter app must be able to work with JS libraries, I intend to use jsQR.
service workers and indexedDB could help you for develop offline route app and offline api.
mdn docs for service workers
I'm not sure that this will fit your particular case: you say that the system can't run a local webserver, but what if you provide the webserver along with your software?
I just discovered get_server: you can find it here. It aims to allow developers to host their own HTTP server by using only flutter, without resorting to external tools or other coding/scripting languages. It allows also (and that's the relevant part) to wrap your flutter web app and make it run on local network.
For now I only tried with a very simple example, but it seems to be working. These are the steps I took:
create a new flutter project: since I needed the webserver to run on Windows, I had to get flutter ready for that (see here for help)
add get_server to the new pubspec.yaml
run flutter build web on your flutter web project, and copy the build/web output
folder in the root folder of the new project (I renamed the folder while copying since flutter might change the content of the web folder)
delete all the content of lib/main.dart
paste this (this the actual content of main.dart)
import 'package:get_server/get_server.dart' as gs;
void main() {
gs.runApp(
gs.GetServerApp(home: gs.FolderWidget('folderName')),
);
}
folderName is the name of the renamed folder containing the flutter web app build.
I ran this on Windows 'device' from AndroidStudio, and my original flutter web app was reachable at localhost:8080 (for now I just used the default options of get_server). I also got the webserver (empty) GUI as a white window: I guess that can be useful for some information regarding the server itself, although, if that windows closes, localhost:8080 becomes unavailable.
But, once released, you should be able to just run the executable from the USB stick, and then connect to it with Chrome.
PS: after some time using GetServer, I had to switch to other packages because of not-so-good docs and support. Now I'm using shelf, but also Alfred is a notable mention.

Problem publishing my Office Add-in to Azure, Office.js not fully loaded error, but works fine from localhost:3000

I've built and tested my add-in using Fabric React. When I sideload it from localhost:3000, everything works fine. I then created an Azure app services website to host it. Updated the manifest XML file to point to the correct URL instead of localhost:3000. I updated all references from Office.initialize to Office.onReady(). Still, every time I sideload the app from the Azure manifest I get the following error:
Office.js has not fully loaded. Your app must call "Office.onReady()"
as part of its loading sequence (or set the "Office.initialize"
function). If your app has this functionality, try reloading this
page.
Any ideas as to why this happens?
I can’t reproduce the issue from my side.
I’d recommend you to debug your add-in via the steps in the following link: Test and debug Office Add-ins

How to run an ionic app with mongodb data?

I am developing an ionic app using mongodb as database. The problem is when I test my app in a browser I can see the data, but when I run it on a physical device the data doesn't display. I tried to inspect it so I found this error message:
Here is the mongod.cfg file:
Can you help me?
From a mobile device you cant access localhost because it refers the current machine.
You can use ngrok for exposing your local web server. After that you just need to replace the http://localhost:3001/ with the ngrok url for testing on you mobile device.

Windows Store App xhr to localhost fails

I have a Win Store App app which uses REST to communicate with a pinpad device attached by USB. It has it's own proprietary http server/software but it seems fairly simple.
In my dev machine and on my test machine all works as expected. However, on my tester's machine it does not. The issue is that the xhr GET is failing. It just times out and returns status 0.
A simple get using a browser is successful, as is a script run in a browser (ie, ff, ch).
I have swapped out xhr for httpClient, jquery.ajax and a direct XMLhttpRequest call - all have the same result. I have tried setting location header for CORS. Tried different formats for the address (localhost, 127.0.0.1, 192... etc). The app will happily get external content (eg google.com).
Has anyone come across something like this before? I suspect it's something to do with how a Windows Store App interacts with the lan but I don't know where else to look.
By default Windows Store apps are blocked from loopback connections to localhost. By default, Visual Studio sets up an exception when debugging and you can set one up yourself for testing or for side-loaded apps with the checknetisolation tool. If your app will be deployed from the store it cannot rely on a loopback exemption.
See Using network loopback in side-loaded Windows Store apps on MSDN:
To add a Windows Store app to the list of apps that are exempt from
the loopback firewall, run checknetisolation loopbackexempt -a
-n=<package family name> from an elevated command prompt. The package family name for a Windows Store app is available from Visual Studio
via the Package.appxmanifest editor on the packaging tab.

Categories