WKWebView Swift - Get Console.log for javascript - wkwebview

Swift version - 4.2 or 5.0
I have WKWebView setup, which loadHTMLString. I am not able to get the console.log error messages that the JS code produce. I want to get this log within the app. Cannot change settings in safari. Thank You.

Related

Broadleaf - running locally - problem getting started the API project

I'm trying to run Heat Clinic 6.0.1 locally following getting started tutorial: https://www.broadleafcommerce.com/docs/core/current/getting-started/running-locally
I managed to run admin and site but not the API project. The application starts without problems but when I go to http://localhost:8082/api/v1/swagger-ui.html I get a 404. In the log I see this exception:
javax.servlet.ServletException: Circular view path [error]: would dispatch back to the current handler URL [/error] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
Also trying to log in directly in the API with user broadleafapi and password gives 404.
My environment: Windows 10, jdk 8, maven 3.6
What's wrong? Can you help me? Thank you
Thanks for the report. I reproduced this and it looks like that with the update to Spring Boot 2.0, we did not appropriately override the updated property that specifies the servlet location to embedded Tomcat. Thus, when you went to /api/v1/swagger-ui.html, the application treats it exactly like that URL which is what gave the 404.
Setting the server.servlet.contextPath=/api/v1 property appropriately stripped off this path as part of the servlet context and resolved the 404.
I tested around a bit and was able to 'Authorize' the app (button at the top right of the Swagger page) with the credentials information that get spit out in the logs:
Basic auth configured with user broadleafapi and password: <<generated>>
then I was able to hit the API endpoints.
The changes you will need to make locally in your project to consume the fix are at https://github.com/BroadleafCommerce/DemoSite/commit/422d1cdc37f847afd8bec0be477ab784cbad2e9d#diff-991c59b6dbb0f619b8570d8f8779eaddR11. You will notice that I moved the original definition in default.properties over to common.properties and I recommend that you do the same. To be clear, follow these steps:
Delete the server.servlet.contextPath entry in `api/src/main/resources/runtime-properties/default.properties
Change server.servletPath in api/src/main/resources/runtime-properties/common.properties to server.servlet.contextPath
Thanks for trying out Broadleaf and the report, sorry for the rough early start!

Request for (gzipped) 'jsf.js' from Mojarra 2.3.3 results in empty response

I used the <f:websocket/> tag in my project with mojarra 2.3.3 and in project stage 'Development' everything was working fine. But when the project was deployed on our QA system with project stage 'Staging', the client produced the JS error "'mojarra' not defined".
This is due to the jsf.js being loaded as a blank file. When I debugged, I found that in com.sun.faces.application.resource.ResourceHelper#getInputStreamFromClientInfo the content of the js file is copied to a GZIPOutputStream which is never finished and thus nothing is written to the wrapped ByteArrayOutputStream (ll. 234-237), resulting in the empty response to my client.
In stage Development the file is delivered uncompressed.
Is this a bug or am I missing something? Is there a configuration for this? Is there a workaround?
I tried setting com.sun.faces.compressJavaScript to false with no luck.
When I call GZIPOutputStream#finish() on the stream before it's written to the ByteArrayInputStream in the debugger, the content of the input stream is correct and sent to the client. I also checked mojarra 2.3.8 but the code seems to be unchanged.
I expect the client to receive the correct js code. It doesn't necessarily have to be compressed.
Addition:
The project is running on a Tomcat 8.5.14 with JDK1.8.0_161 and I'm using Primefaces (6.2).
I created a miminal working example here which doesn't use Primefaces. It doesn't actually push anything into the websocket channel but the relevant thing here is the JS error when the index.xhtml is loaded.
It's also tested with Java 1.8_202, Tomcat 8.5.37, Mojarra 2.3.8. It's working (loading the jsf.js that is) with Mojarra 2.2.14.

How to programmatically open the Bluetooth settings in iOS 10

I'm trying to access the Bluetooth settings through my application using swift.how can access bluetooth setting?
Xcode version - 8.0
swift - 2.3
iOS - 10
func openBluetooth(){
let url = URL(string: "App-Prefs:root=Bluetooth") //for bluetooth setting
let app = UIApplication.shared
app.openURL(url!)
}
Swift 3.0: working up to iOS 10
Note: This URL is "private API". The app will be rejected by App Store reviewers if used.
You will not be able to use the solution by #Siddharth jain. The Problem: The app will be rejected by Apple with a warning that you should never use non-public APIs anymore. Otherwise, you could risk your developer program.
As far as I know, all you can do is open the iPhone settings in general (or get lead to your app settings if there are some. To do so you need the following code
guard let url = URL(string: UIApplication.openSettingsURLString) else {
// Handling errors that should not happen here
return
}
let app = UIApplication.shared
app.open(url)
By this, you will always get a URL you can use without any problems with apple review.
Until now you cannot access to bluetooth settings from your app from iOS 10.
you can see the following link to keep your mind at peace.
https://forums.developer.apple.com/message/146658#146658
Opening the Settings app from another app
Now that iOS 15 seemed to have broken auto-reconnect for known Bluetooth devices (other than audio gadgets), it's extremely annoying. If someone finds a solution, App Store-safe or not, I'm all ears.

Output to Chrome console from Node.js

I'm looking for a way to output Node variables directly into the google chrome browser console. The same way a console.log() works on the client side. Something like this for php. This would greatly speed up development.
NOTE:
Since the old answer (written in september 2014) refers to an older version of node-inspector, my instructions are not relevant anymore in 2017. Also, the documentation has gotten a lot better, so I have updated my original answer:
node-inspector is what you need.
It opens up an instance of Chrome with its developer tools for debugging.
It's also easy to use:
1. Install
$ npm install -g node-inspector
2. Start
$ node-debug app.js
Source: https://github.com/node-inspector/node-inspector
You might want to try NodeMonkey - https://github.com/jwarkentin/node-monkey
I know it's an old question but came on top of my Google search so maybe somebody will find my answer useful.
So you can use node --inspect-brk index.js
Now, all you have to do is basically just type chrome://inspect in your Chrome address bar and click Open dedicated DevTools for Node
In DevTools, now connected to Node, you’ll have all the Chrome DevTools features you’re used to:
Complete breakpoint debugging, stepping w/ blackboxing
Source maps for transpiled code
LiveEdit: JavaScript hot-swap evaluation w/ V8
Console evaluation with ES6 feature/object support and custom object formatting
Sampling JavaScript profiler w/ flamechart
Heap snapshot inspection, heap allocation timeline, allocation profiling
Asynchronous stacks for native promises
Hope that helped.
The closest thing to this I've seen is Node JS console object debug inspector
See this post for usage and potential issues: http://thomashunter.name/blog/nodejs-console-object-debug-inspector/
For users with nodejs on linux via ssh-shell (putty):
Problem with nodejs on linux-ssh-shell is, that you have no browser connected.
I tried all this solutions, but didnt get it to work.
So i worked out a solution with firebase (https://firebase.google.com), because my project uses firebase.
If you are familiar with firebase, than this is a great way. If not, firebase is worth using in combination with nodejs - and its free!
In the server-side-script (started with node) use a own function log():
// server-side:
// using new firebase v3 !
var fbRootRef = firebase.database();
var fbConsoleRef = fbRootRef.ref("/console");
var log = function(args) {
fbConsoleRef.set({'obj': args});
}
// inside your server-code:
log({'key':'value'});
On client-side you create a firebase-reference on this console-object:
// client side:
fbRootRef.child('/console').on('value', function(d) {
var v = d.val();
console.log(v);
});
Now everything logged on server-side with the log() - function is transferred in realtime to the firebase-database and from there triggering the client-console-reference and logged into the browsers console.
If anyone needs help, i will explain in more detail and could give a more extended version of this logging with types (console./log/warn/info), grouping with title-info (i.e. server says: (filename + line).
Setting up firebase for your project is done in max 30 minutes, inserting the console-function in 30 minutes. I think its worth the time!
You can use bonsole, a simple way to log something in browser. Even in Linux, you can go to the LAN's ip to check it.
The most simple way with least dependencies is using a WebSocket connection to send the messages to the browser. Any WebSocket example you can find on the internet will suffice to accomplish this. Everything else requires to be heavily integrated into the host system and wouldn't work if you want to actually run this on a remote server. You can also send commands to the server directly from the browser console this way.
Links:
https://www.npmjs.com/package/websocket
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications

Chrome extension: "Uncaught Error: "getBackgroundPage" can only be used in extension processes...."

I published a chrome extension to testers only. The app seems to work very well. I don't see any errors when inspecting the console for the popup or the background page. However, I get the following error when inspecting the console for any web page: "Uncaught Error: "getBackgroundPage" can only be used in extension processes. See the content scripts documentation for more extensions/schema_generated_bindings.js:418"
This app contains several JavaScript files, but each one includes the code within a self executing function. The "getBackgroundPage" calls are in the JavaScript files.
Could you please help? Isn't the app I built an isolated module independent from any web page? How can I prevent this error from happening?
I had the same error when I was trying to communicate with the background page from my content script. The correct way of doing it is via Message Passing. It is very well documented here : https://developer.chrome.com/extensions/messaging.html

Resources