I'm playing with a thermal printer to work with WebUSB.
Here is the minimal Glitch demo (please note this demo may show your connected usb devices):
preview: https://canary-adjoining-garlic.glitch.me
code: https://glitch.com/edit/#!/canary-adjoining-garlic
I'm able to select the (any) device. But unable to call device.open().
document.getElementById("print-button-usb").addEventListener("click", () => {
console.log('clicked');
navigator.usb.requestDevice({ filters: [] })
.then(device => {
console.log('device paired', device);
console.log(device.vendorId, typeof device.vendorId);
return device;
})
.then(device => device.open()) // Error here <<-------------------------------------!
.catch(err => console.error("my err", err));
})
Not only that printer, but I'm unable to open any connected shown devices. Can someone point out what am I missing here?
Environment details:
Ubuntu 22.04.1
Chrome Version 107.0.5304.121
I've been following this guide: https://web.dev/usb
Update : (Debug informations)
My chrome://device-log says: Failed to open /dev/bus/usb/001/005: Permission denied (13). I tried to cat that node:
$ cat /dev/bus/usb/001/005
#V �2 �##%
$ pwd
/dev/bus/usb/001
$ ls -l
total 0
crw-rw-r-- 1 root root 189, 0 Nov 30 23:13 001
crw-rw-r-- 1 root root 189, 1 Nov 30 23:13 002
crw-rw-r-- 1 root root 189, 2 Nov 30 23:13 003
crw-rw-r-- 1 root root 189, 3 Nov 30 23:13 004
crw-rw-r-- 1 root lp 189, 4 Dec 1 00:07 005
In the above image,
Integrated_Webcam_HD: laptop camera
KT USB Audio: my headphones connected via usb-c
CB-GK-16 Firefly: Additional keyboard
USB Portable Printer: the thermal printer I'm playing with
I tried to connect my phone over usb and tried to pair - I was able to pair it.
In this list, the "Pixel 3" device was the only device I was able to successfully connect. All others are returning the "Access Denied" error.
Same problem here using FTDI device.
I was able to get the device but not I could not open it with exactly the same error. I was using windows 10 by the way. Problem was solved by changing the driver from FTDI custom driver to WinUsb using zadig.
note:
after doing so, the device could not be used by the previous .NET application and it is only accessible by the browser.
I've a NW.JS desktop app keeps crashing because of webpage errors.
I'm trying to open this webpage inside my app - URL
As soon as the pages get loaded my app starts to crash with the following error:
[3491:775:0210/215448.347299:FATAL:native_extension_bindings_system.cc(214)] Check failed: schema. arcAppsPrivate
0 nwjs Framework 0x000000011243a239 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 14936185
1 nwjs Framework 0x000000011239a8f3 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 14282547
2 nwjs Framework 0x00000001123ad73f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 14359935
3 nwjs Framework 0x00000001123ae5ee v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 14363694
4 nwjs Framework 0x0000000111ad1838 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5070456
5 nwjs Framework 0x0000000111a9900a v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 4838986
6 nwjs Framework 0x0000000111a98f7d v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 4838845
7 nwjs Framework 0x0000000111ad4de8 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5084200
8 nwjs Framework 0x0000000111ad48b3 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5082867
9 nwjs Framework 0x0000000111ad4253 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5081235
10 nwjs Framework 0x0000000111ad447f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5081791
11 nwjs Framework 0x0000000110f02f73 v8::internal::FixedArray::SetAndGrow(v8::internal::Isolate*, v8::internal::Handle<v8::internal::FixedArray>, int, v8::internal::Handle<v8::internal::Object>) + 1763
12 nwjs Framework 0x0000000110f02321 v8::internal::Object::GetProperty(v8::internal::LookupIterator*, bool) + 3041
13 nwjs Framework 0x0000000110f01814 v8::internal::Object::GetProperty(v8::internal::LookupIterator*, bool) + 212
14 nwjs Framework 0x0000000111048bf5 v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, bool*) + 181
15 nwjs Framework 0x000000011104f103 v8::internal::Runtime::DefineObjectOwnProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::StoreOrigin, v8::Maybe<v8::internal::ShouldThrow>) + 13571
16 ??? 0x0000003707f0a8f8 0x0 + 236356413688
17 ??? 0x0000003707fa17b6 0x0 + 236357031862
18 ??? 0x0000003707e8c862 0x0 + 236355897442
Task trace:
0 nwjs Framework 0x0000000115920992 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 70406098
1 nwjs Framework 0x00000001125fe106 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 16787270
IPC message handler context: 0x95373B38
Crash keys:
"discardable-memory-free" = "2715648"
"discardable-memory-allocated" = "4194304"
"view-count" = "3"
"extension-1" = "jhedmmohalmhagooekjmhcjkphpnfmfa"
"num-extensions" = "1"
"blink_scheduler_async_stack" = "0x115920992 0x1125FE106"
"v8_code_space_firstpage_address" = "0x3700000000"
"v8_map_space_firstpage_address" = "0x3708180000"
"v8_ro_space_firstpage_address" = "0x3708000000"
"v8_isolate_address" = "0x7ff2f8c44000"
"variations" = "f475deb0-f475deb0,313957be-3ef44cd2,7e184ca7-2ec1a7e,60c843ad-3f4a17df,3fa8d059-3fa8d059,3c98d047-3f4a17df,8950ab95-3f4a17df,6cbcf5b7-3f4a17df,4701a278-3f4a17df,4749874c-a300a3e6,65570806-377be55a,6aa15a86-9d8c1aae,8e3b682d-3f4a17df,722b8030-3f4a17df,3042ad4b-ad2fa222,e4a357e9-3f4a17df,3fd33f16-fa281276,5252c71-3f4a17df,e79de56c-dee0823,8bccc03b-3f4a17df,178e8b37-3f4a17df,facdb7bf-3f4a17df,69d4ebd5-3f4a17df,9e5c75f1-30e1b12b,255dfea8-cf12f279,a083757a-d6a08b38,e4cbd6c7-3f4a17df,f7a3ec9-bd336006,3487aa71-84708353,23a898eb-fc93cf74,d3566fbd-c6f74b94,4ea303a6-3f4a17df,7048821f-7b0f7072,ef4764d7-c9f4d4ef,931c5f72-3f4a17df,ade3efeb-e1cc0f14,32d6b1fe-3f4a17df,ae82076d-3f4a17df,17b84626-3f4a17df,8d7344de-3f4a17df,1bb6a450-3f4a17df,3e7d7783-f38a9353,90a7075b-725c8fbe,1d606bb5-8d14c5d8,a0da97d6-3f4a17df,3b96a1d-3f4a17df,248e3a0-3f4a17df,dba92675-f23d1dea,5306c29b-9cbf73ff,f8a7f5e4-d6a08b38,e87da360-3f4a17df,39ec51c3-572726d7,77e44b8e-3f4a17df,6c5f69af-3f4a17df,bef5c006-3f4a17df,fc7e4d22-3f4a17df,7638c831-857014ec,a112f012-3f4a17df,6e08fc3e-3f4a17df,8470b833-3f4a17df,6be2e990-3f4a17df,47d92407-5b5edf5b,4b9a5bc0-efbbc50a,49a20295-49a20295,f2cb61f-3f4a17df,8c8d8faf-3f4a17df,727723f1-40193c20,b012722b-3f4a17df,d8692482-fe3984ae,29c62d4-3f4a17df,7760b5b2-3f4a17df,ad4acdda-3f4a17df,234de0a0-ace4e138,b1ceb06f-3f4a17df,ca5a2953-ff983c32,4e3ec83a-e4938e2c,7f655da7-3f4a17df,248c3fbd-3f4a17df,6cb5e962-3f4a17df,bf4029fe-1776d9e,6a5f15b-3f4a17df,61a655b5-3f4a17df,54410569-3f4a17df,6aa685f2-dcaf2061,f48c01d3-6eb2bd2b,89a16501-3f4a17df,"
"num-experiments" = "86"
"switch-21" = "--user-data-dir=/path/temp/userdatadir/profile2"
"switch-20" = "--user-data-dir=/path/temp/userdatadir/profile2"
"switch-19" = "--disable-gpu"
"switch-18" = "--field-trial-handle=1718379636,962445429152936292,7087525159415"
"switch-17" = "--shared-files"
"switch-16" = "--launch-time-ticks=8302334130"
"switch-15" = "--renderer-client-id=6"
"switch-14" = "--enable-main-frame-before-activation"
"switch-13" = "--enable-gpu-memory-buffer-compositor-resources"
"switch-12" = "--enable-zero-copy"
"switch-11" = "--num-raster-threads=4"
"switch-10" = "--lang=en-GB"
"switch-9" = "--disable-gpu-compositing"
"switch-8" = "--no-zygote"
"switch-7" = "--file-url-path-alias=/gen=/path/software/nwjs-sdk-"
"switch-6" = "--no-sandbox"
"switch-5" = "--display-capture-permissions-policy-allowed"
"switch-4" = "--extension-process"
"switch-3" = "--nwjs"
"switch-2" = "--nwapp-path=/path/projects/soft-v2/nw"
"switch-1" = "--user-data-dir=/path/temp/userdatadir/profile2"
"num-switches" = "24"
"osarch" = "x86_64"
"pid" = "3491"
"ptype" = "renderer"
[0210/215448.351355:WARNING:process_memory_mac.cc(93)] mach_vm_read(0x7ffeebe70000, 0x2000): (os/kern) invalid address (1)
[3486:12803:0210/215448.434605:ERROR:ssl_client_socket_impl.cc(995)] handshake failed; returned -1, SSL error code 1, net_error -200
[3486:18691:0210/215448.806969:WARNING:sqlite_persistent_store_backend_base.cc(171)] Failed to post task from FlushAndNotifyInBackground#net/extras/sqlite/sqlite_persistent_store_backend_base.cc:219 to client_task_runner_.
[3486:18691:0210/215448.807044:WARNING:sqlite_persistent_store_backend_base.cc(171)] Failed to post task from FlushAndNotifyInBackground#net/extras/sqlite/sqlite_persistent_store_backend_base.cc:219 to client_task_runner_.
[3475:775:0210/215448.857362:WARNING:pref_notifier_impl.cc(40)] Pref observer for media_router.cast_allow_all_ips found at shutdown.
There's a similar issue already open - URL
I tried upgrading/downgrading NWJS version.
Tried passing the
flags suggested in one of the comments of the github issue
Tried
adding try catch to window open like below:
try {
nw.Window.open(url);
}
catch(err) {
log.info("Got error")
}
Tried different OS (Mac & Windows)
It crashes with both 32 Bit NWJS and 64 Bit. Tried both of them.
But nothing is working.
However, another page link of the same website is working, which does not have console errors and much content. URL
Need help in understanding the problem and fixing it.
Also, I'm surprised as well, since a webpage can cause the NWJS desktop app to crash.
I could be wrong, but I think the feature you're looking for is:
nw.Shell.openExternal('https://seller.flipkart.com/sell-online');
That page just looks like a normal website, not a desktop app that would need access to Node.js. So you can just use nw.Shell.openExternal to open the page in the user's default browser. For security reasons, it's best to avoid using node-remote unless you are running a local webserver and pointing it to "http://localhost:8000" (or whatever port).
So I'm trying to connect to openEEG upon running the claimInterface() function I get
NetworkError: Unable to claim interface
lsusb shows this problem is likely because some MSI driver is running on the same driver
Output of lsusb -v -s4
Bus 002 Device 004: ID 1770:ff00
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x1770
idProduct 0xff00
bcdDevice 1.10
iManufacturer 1 MSI EPF USB
iProduct 1 MSI EPF USB
iSerial 1 MSI EPF USB
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 34
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 2mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 33 US
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 57
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 10
Device Status: 0xa630
(Bus Powered)
Bus 001 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0403 Future Technology Devices International, Ltd
idProduct 0x6001 FT232 USB-Serial (UART) IC
bcdDevice 6.00
iManufacturer 1 FTDI
iProduct 2 FT232R USB UART
iSerial 3 A105XV9J
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 90mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 2 FT232R USB UART
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Device Status: 0x0000
(Bus Powered)
I originally tried adding 255 as the classCode on navigator.usb.requestDevice because the documentation said I can do that, but they don't have the same IDs so that was pointless. Also upon reconnecting I can only get lsusb to output of the MSI driver even though Chrome picks it up and I got an access denied error.
which is strange because I changed the udev rules and used sudo chmod -R 777 * In dev/bus/usb
I then found in folder "001" a file that I previously had to manually change the permissions of thinking it was the MSI driver but this time the original file was deleted in place of one named "007" instead of "005" (probably because I tried plugging the device in twice)
So this must be a combination of MSI security features? and OpenEEG creating a new file every time it's loaded?
The only solution I can think of is to delete a file that I don't understand and change the permissions every time it's plugged in. both of which are very prohibitive for uses especially since I want my website to work across a broad range of devices and operating systems
PS: Using Linux Mint if that's relevant and here is my code(I don't think it's the problem) that is being run with on local node.js server
document.addEventListener('DOMContentLoaded', event => {
let button = document.getElementById('connect')
button.addEventListener('click', async() => {
var device
const VENDOR_ID = 0x0403
const PRODUCT_ID = 0x6001
const CLASS_CODE = 255
device = await navigator.usb.requestDevice({
filters: [{
vendorId: VENDOR_ID,
productId: PRODUCT_ID,
classCode: CLASS_CODE
}]
})
console.log('opening..')
await device.open()
console.log('open!')
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0)).catch(error => { console.log(error + 'eeeeeeerrrr ' + device.configuration.interfaces[0].interfaceNumber); });
console.log(device);
await device.close().catch(error => { console.log(error + 'eeeeeeerrrr'); });
});
})
EDIT/UPDATE: lsusb returns nothing when not connected the two drivers are coming from the same input???????
When you connect your device on the USB port Linux loads its driver and claim the device for itself.
If you want to use it somewhere else just unload the driver:
$ sudo modprobe -r ftdi_sio
If you reboot your computer the driver will load again and you'll have to unload it manually. If you want to keep it unloaded you can do:
$ echo "ftdi_sio" | sudo tee -a /etc/modules
I can understand why it got you confused, considering the output of lsusb is not that clear but I think the other MSI driver is for the root USB controller on your computer. If you remove it you won't be able to see your ports or anything connected to them.
If unloading the driver does not fix your problem maybe you're not claiming the correct device. You can find out more reading the log file if you write on your navigation bar chrome://device-log/
I am extracting continuously updating data from an html tag using javascript in the chrome developer tools console and sending it to a webserver (python flask) to be able to further process the data within a python application.
The problem is that 50% of the time, the request takes less than 5 ms, BUT the other 50% of the time the request takes around 300ms which is too much as the application I intend to build is latency sensitive.
How can I reduce the time required for ALL html POST requests down to less than 5ms?
The javascript code used in chrome is:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:5000/mqtt/", true);
xhr.setRequestHeader('Content-Type', 'text/plain');
console.log(Date.now());
xhr.send(Date.now().toString());
The python code (python 3.6) is:
import time
from flask import request, Flask
from flask_cors import CORS
application = Flask(__name__)
CORS(application)
#application.route('/mqtt/', methods=['POST'], strict_slashes=False)
def process_prices():
start = time.time()
data = request.get_data().decode("utf-8")
time_decoding = time.time()
print('timestamp javascript', data)
print('timestamp python', time.time()*1000)
print('total time: ', int((time.time()-start)*1000))
print('decoding time: ', int((time_decoding - start) * 1000))
return "OK"
if __name__ == '__main__':
application.run(debug=False)
Results:
When I execute the javascript code the first time, the difference between the timestamp collected in the javascript code and the timestamp measured in python is around 300ms. If I run the same javascript code again within 10 seconds from running it the first time, the time difference is reduced to less than 5 ms. If I wait 10-11 seconds for the code to run the second time, the code again takes 300ms. if I keep re-executing the javascript code repeatedly every 2-3 seconds, every second time the request takes 300ms to be picked up by the server and every other time it only takes 1-5 ms.
This makes me think that either chrome or the flask server are somehow being configured in a way that adds additional latency and that it should be possible to reduce the time required for ALL requests to get to the webserver down to less than 5 ms rather than only half of them.
Output from flask webserver:
timestamp javascript 1555342312986
timestamp python 1555342313289.659
total time: 1
decoding time: 0
127.0.0.1 - - [15/Apr/2019 17:31:53] "POST /mqtt/ HTTP/1.1" 200 -
timestamp javascript 1555342314901
timestamp python 1555342314903.6602
total time: 0
decoding time: 0
127.0.0.1 - - [15/Apr/2019 17:31:54] "POST /mqtt/ HTTP/1.1" 200 -
timestamp javascript 1555342315912
timestamp python 1555342316217.7195
total time: 1
decoding time: 0
127.0.0.1 - - [15/Apr/2019 17:31:56] "POST /mqtt/ HTTP/1.1" 200 -
My question is, what is the most efficient configuration for PhantomJS tests.
Currently I have 1 instance of PhantomJS running and every instance can have 2 tabs opened (dev env).
Is it better to have more instance of phantomjs or opened tabs, and if tabs, what is the upper limit of PhantomJS.
CPU:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i5-3210M CPU # 2.50GHz
stepping : 9
microcode : 0x19
cpu MHz : 2494.316
cache size : 3072 KB
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc up rep_good nopl xtopology nonstop_tsc pni pclmulqdq monitor ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx rdrand hypervisor lahf_lm
bogomips : 4988.63
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
Memory:
total used free shared buffers cached
Mem: 2515896 1155828 1360068 0 171648 622668
More information:
I would like to handle multiple tests at once with as less memory as possible. Now I am running two pages per phantom instance, and already I am having issues with network requests. I have a timeout of 20s and if a specific network request is not finished in that time, test fails.
Test is successful if I only run one page in one PhantomJS instance, but that is not optimal, because we will be running more then 1000 tests, and I would like to arrange tests in multiple pages across multiple phantomjs instances.
Example:
10 phantomjs instances
every phantomjs instance can run 30 pages
Now why when running multiple pages in one instance, does the network request lag so much?