How to see console.log messages of a website using android emulator?
From Rich Chetwynd's short article "Javascript debugging on Android browser".
You can log javascript errors and console messages from your Android device or emulator. To do this you first need to install the Android SDK and USB drivers and enable USB debugging on the actual device.
To check if the device is connected correctly you can run the following cmd from your Android SDK tools directory and you should see a device in the list
c:\android sdk..\platform-tools\adb devices
You can then use the Android Debug Bridge to filter debug messages so that you only see browser related messages by running the following cmd.
c:\android sdk..\platform-tools\adb logcat browser:V *:S
By default the log is written to stdout so you will see any Javascript errors or console.log messages etc written to the cmd window.
Further details: Logcat CLI tool docs.
If you have started the emulator from Eclipse with the ADT plugin, you will see all JavaScript console logs directly under the LogCat view :
Window -> Show View -> Android -> LogCat
If you are using Android Studio; you can open your Logcat (Alt+6) and filter for: :CONSOLE
Filtering for only :CONSOLE (rather than INFO:CONSOLE) will display all types of console messages (including ERROR, WARN, etc).
You could add some JavaScript temporarily like...
var console = {
log: function(msg) { alert(msg); }
};
Ugly as hell, but it works.
I hijacked the console.log using this code:
function logManager() {
var self = this;
self.init = function () {
console.log('logmanager initialized');
var old = console.log;
self.logger = document.getElementById('log');
console.log = function (message, options) {
if (typeof message == 'object') {
self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />' + self.logger.innerHTML;
} else {
self.logger.innerHTML = message + '<br />' + self.logger.innerHTML;
}
}
}
self.toggleLogVisibility = function () {
return $(self.logger).toggle();
};
}
And consume it like so in your html with your own styling (absolute top right is what I used)
<div id="log" class="log">
Application loaded...
</div>
And in your jscript (run this on page loaded as the log element has to exist)
document.lmgr = new logManager();
document.lmgr.init();
Open this url on your chrome
chrome://inspect
Command - get log from the emulator
adb -e logcat
adb.exe can be found at $your_installation_path$\android sdk\platform-tools
more detailed
https://learn.microsoft.com/ru-ru/xamarin/android/deploy-test/debugging/android-debug-log?tabs=windows
If you cannot run adb logcat browser:V *:S because of zsh, you need to run noglob adb logcat browser:V *:S. Rationale: https://github.com/ohmyzsh/ohmyzsh/issues/2901
Related
In VS code editor, ng serve command opening "How do you want to open this file?" dialog box in
The answer by Petr Freiberg helped get me to what I believe is a better solution. Instead of deleting files that may or may not actually be important for the system, we should update our PATH variables so that the "correct" command is found first.
In my situation, I had my npm paths in this order:
C:\Users\Me\AppData\Roaming\npm\node_modules\#angular\cli\bin
C:\Users\Me\AppData\Roaming\npm
I just switched the order so that C:\Users\Me\AppData\Roaming\npm came first.
The issue is that the terminal is finding the first "command match" which may just be a file, so that is why it is asking where you want to open it.
I did run the command Run Get-Command -All ng | ForEach-Object Path as Petr suggested, which called out the order issue I describe here.
I encountered a similar problem when executing a Docker command within Visual Studio Code. I also got a window asking "How do you want to open this file?". I think the problem is not in Visual Studio Code, but in PowerShell, which Visual Studio Code uses.
I solved it like this:
Run Get-Command -All docker | ForEach-Object Path
Among the file paths returned, remove those that do not end in *.exe (use
Remove-Item):
For ng it should be same.
Credits: https://stackoverflow.com/a/63981418/1816014
i have faced the same issue, while trying to run ng -v or ng --version, it pops open a Open option editor, which gives following ng.js text...
#!/usr/bin/env node
'use strict';
// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch (_) {
// If an error happened above, use the most basic title.
process.title = 'ng';
}
// This node version check ensures that extremely old versions of node are not used.
// These may not support ES2015 features such as const/let/async/await/etc.
// These would then crash with a hard to diagnose error message.
// tslint:disable-next-line: no-var-keyword
var version = process.versions.node.split('.').map((part) => Number(part));
if (version[0] % 2 === 1 && version[0] > 14) {
// Allow new odd numbered releases with a warning (currently v15+)
console.warn(
'Node.js version ' +
process.version +
' detected.\n' +
'Odd numbered Node.js versions will not enter LTS status and should not be used for production.' +
' For more information, please see https://nodejs.org/en/about/releases/.',
);
require('../lib/init');
} else if (
version[0] < 12 ||
version[0] === 13 ||
(version[0] === 12 && version[1] < 14) ||
(version[0] === 14 && version[1] < 15)
) {
// Error and exit if less than 12.14 or 13.x or less than 14.15
console.error(
'Node.js version ' +
process.version +
' detected.\n' +
'The Angular CLI requires a minimum Node.js version of either v12.14 or v14.15.\n\n' +
'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
);
process.exitCode = 3;
} else {
require('../lib/init');
}
what is the error here, i tried uninstall clear cache and install but still same error....
I've recently tried to install the QDK via the VSCode extension in my Windows 10 Desktop and VSCode wasn't able to find the Microsoft libraries even after I was able to execute the code by the dotnet run command on the terminal. The code was the sample project code described in the create new project part of the tutorial. I also didn't have .NET SDK so I installed it but it seems to be working fine. In computers I got problems all the code, all related to not finding the namespaces.
namespace QuantumRNG {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
operation GenerateRandomBit() : Result {
using (q = Qubit()) {
H(q);
return MResetZ(q);
}
}
operation SampleRandomNumberInRange(max : Int) : Int {
mutable output = 0;
repeat {
mutable bits = new Result[0];
for (idxBit in 1..BitSizeI(max)) {
set bits += [GenerateRandomBit()];
}
set output = ResultArrayAsInt(bits);
} until (output <= max);
return output;
}
#EntryPoint()
operation SampleRandomNumber() : Int {
let max = 50;
Message($"Sampling a random number between 0 and {max}: ");
return SampleRandomNumberInRange(max);
}
}
Do you see any error messages in the output console?
To see the output console select "View: Toggle Output" (Ctrl + Shift + U) and select "Q# Language Extension" from the drop down list.
If the drop down list doesn't show "Q# Language Extension" then it probably means that the language-server that gets downloaded on first run is still downloading, so give it a minute or so (depending on your internet connection).
I think I also had the same problem. The .Net SDk which you have downloaded automatically creates a path in the environment variable by the name "%USERPROFILE%.dotnet\tools" so delete this and add "C:\Program Files\dotnet\sdk" or copy the path of dotnet SDK from the drive where you have installed dotnet and create a new environment variable under user variable. This might solve your namespace problem.
I'm developing an add-in for Microsoft Word 2016 using office js version 16.0.8626.1000. I use a web service to retrieve a document in base64 format and then I create a new Word instance with that.
The problem is that whenever I run the add-in from my server (not from visual studio debugger) it opens the document but the add-in frame displays an error
First Instance:
Second Instance:
This doesn't happen if I run the add-in from visual studio debugger, it opens the new instance without the frame.
This is my code
Office.initialize = function (reason) {
// Checks for the DOM to load using the jQuery ready function.
$(document).ready(function () {
$('#get').click(function () {
openWord();
});
});
}
This how I retrieve the document (without real url):
function openWord() {
getDocumentAsBase64(function (data) {
Word.run(function (context) {
var myNewDoc = context.application.createDocument(data);
context.load(myNewDoc);
return context.sync()
.then(function () {
myNewDoc.open();
context.sync();
})
.catch(function (myError) {
//otherwise we handle the exception here!
updateStatus(myError.message);
})
}).catch(function (myError) {
updateStatus(myError.message);
});
});
}
function getDocumentAsBase64(callback) {
$.ajax({
url: 'http://myurltomydocument.com/getFile',
data: "{}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (response) {
callback(response.d);
},
error: function (response) {
updateStatus(response.d);
}
});
}
EDIT -- 8/12/2017
This is the manifest that I'm currently using if anyone wants to replicate the problem with Office 2016
I don't read Spanish, but the error mentions Visual Studio. I think Office is still trying to run a version that was sideloaded with Visual Studio and it's telling you that it can't do that. The problem might be the manifest. I notice that it still has the string ~remoteAppUrl in many places. When you are debugging with VS, this string is automatically replaced with the localhost URL, but you need to manually change all these to your web service's domain and sideload the new manifest when you are going to run it from the web service.
EDIT 12/11/17:
If that doesn't fix it, try clearing the Office cache. Details are at: Clear the Office cache
Edit 12/19/17:
Try this:
Go on File->Info->Check for Issues -> Inspect Document -> Inspect.
Then on Task Pane Add-ins click Remove All
Finally I found the solution to this problem.
First I downloaded Office 2016 Administrative Template Files.
When you run it, it will extract a bunch of files and folders.
Enter admx folder and copy the whole content to C:\Windows\PolicyDefinitions.
Do a gpupdate /force under CMD (or Powershell) as an administrator.
Run gpedit.msc and find the Administrative Template for Office 2016 then Updates (PC configuration >> Administrative Template >> Microsoft Office 2016 >> Updates >> Update Channel) and set the Update Channel to Montly Channel.
I'm on Version 1711 (compilation 8730.2127 click and run) and everything is working good now.
EDIT 9/1/2018:
The error started showing up again. The only thing I did was attaching the runtime logging to debug my add-in manifest. This is still unsolved.
With Zend Framework 1.12 you can use Zend_Log_Writer_Firebug to write log information to the firebug console. Is there a way to pass the output to the chrome debugger console?
$logger = new Zend_Log();
$writer = 'production' == $this->getEnvironment() ? new Zend_Log_Writer_Stream(APPLICATION_PATH .'/../data/logs/app.log') : new Zend_Log_Writer_Firebug();
$logger->addWriter($writer);
if ('production' == $this->getEnvironment()) {
$filter = new Zend_Log_Filter_Priority(Zend_Log::DEBUG);
$logger->addFilter($filter);
}
$this->_logger = $logger;
Zend_Registry::set('log', $logger);
}
I am using Chrome Logger. It's a little bit more complicated than with Firebug but no big deal:
install the extension for your Chrome browser
include ChromePHP in your composer.json (that's the way I do it - if you have a different application include path, put it there)
now you can use Zend\Log\Writer\ChromePHP to send debug-information to your Chrome-console.
Context:
Earlier this year Facebook updated their android app without using the google play services : http://liliputing.com/2013/03/facebook-pushes-android-update-to-enable-silent-updates-bypassing-the-play-store.html
I would like to try a similar thing with my android app.
(I'm aware of the implications so please don't post regarding the same.)
Description:
I have gone through the the related Android classes Package Manager - Androidxref and resources like: Install apps silently, with granted INSTALL_PACKAGES permission but could not find any non-rooted method.
Ways like:
public static int installAPP(String absolutePath){
int status = -1;
File file = new File(absolutePath);
if(file.exists()){
try {
String command = "adb install -r " + StringUtil.insertEscape(absolutePath);
Process install = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
status = install.waitFor();
} catch (Exception e) {
Log.e(TAG, "Not Installed!");
} finally { return status;}
}
}
works just fine, but then again it's for rooted devices.
Any information/hints for possible ways of doing and and any relevant information/hacks regarding the same is much appreciated.
Thank You.
PS. I am working on a ROM.