How to run firefox in native app of an extension? - firefox-addon

I'm trying simple modify an extension example to run firefox,but I get a message prompt :
Firefox is already running,but is no responding. To open a new new window, you must firest close the existing Firefox process, or restart your system.
#!/usr/bin/env python3
import sys
import json
import struct
import subprocess
try:
# Python 3.x version
# Read a message from stdin and decode it.
def getMessage():
rawLength = sys.stdin.buffer.read(4)
if len(rawLength) == 0:
sys.exit(0)
messageLength = struct.unpack('#I', rawLength)[0]
message = sys.stdin.buffer.read(messageLength).decode('utf-8')
return json.loads(message)
# Encode a message for transmission,
# given its content.
def encodeMessage(messageContent):
encodedContent = json.dumps(messageContent).encode('utf-8')
encodedLength = struct.pack('#I', len(encodedContent))
return {'length': encodedLength, 'content': encodedContent}
# Send an encoded message to stdout
def sendMessage(encodedMessage):
sys.stdout.buffer.write(encodedMessage['length'])
sys.stdout.buffer.write(encodedMessage['content'])
sys.stdout.buffer.flush()
while True:
receivedMessage = getMessage()
if receivedMessage == "ping":
run_result=subprocess.run('firefox -P firefox_word ',shell=True,stdout=subprocess.PIPE)
sendMessage(encodeMessage("pong3"))
except AttributeError:
pass
My purpose is open a local html file by my extension or native app of my extension.

I had a similar issue a while ago, also when I was experimenting with WebExtensions examples. I think the problem is with your Firefox profile. The solution that worked for me was to create a new profile, then (after a day or so) reopen the previous profile. It has been fine since then. I do not know any more details about the problem.
The Mozilla page "Firefox is already running but is not responding" error message - How to fix it describes this solution as well as a number of others (which I tried, but did not have success with).
You can start the Firefox Profile Manager as per the following instructions (see here for complete details):
If Firefox is open, close Firefox:
Press Windows Key + R on the keyboard. A Run dialog will open.
In the Run dialog box, type in: firefox.exe -P Click OK. The Firefox Profile Manager (Choose User Profile) window should open.
Create a new profile, click 'Start Firefox'
To open your previous profile, launch Profile Manager again and select your default profile

For me I need work in same profile,now my solution is made a shell script as daemon to read a fifo and my native app of my extension write that fifo when I need run firefox.
Note you need run that daemon outside the native app of extension.

Related

where to get the user input in vs code? using dart

I am building a dart program to get the user input. when running the program using the run button I get the output in the output window but I cannot type in it. tried using the terminal to run the program and it worked well. so I want to know what is the right way to take the input from the user?
import 'dart:io';
void main() {
print("enter your name: ");
var name = stdin.readLineSync();
print("hello mrs ${name}");
}
From file -> Preferences -> Settings
search for "Dart: Cli Console"
Dart: Cli Console
Then change the drop-down menu into -terminal-
now you can run again your code and check
you can type in the terminal and your code will work.
In fact the right way using terminal as you did. It's not a fail. It's just how it works.
The answer regarding using the correct vs-code console is correct but you should also check out the dcli package and it's ask function.
Disclaimer: I'm the author of dcli.

How to record screen while testing in Robot framework Appium?

I'm looking the way how to record screen on Robot framework Appium.I've check on Appium Robot Framework Doc but it doesn't describe about it but i have try to write custom lib with python but it's doesn't support.
import os
import subprocess
from appium import webdriver
from robot.api import logger
desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '12.3.2'
desired_caps['bundleId'] = 'xxxxxx'
desired_caps['udid'] = 'xxxxxxx'
desired_caps['deviceName'] = 'iPhone'
driver = webdriver.Remote("http://localhost:4723/wd/hub",desired_caps)
def start_screen_recording():
driver.start_recording_screen()
def stop_screen_recording():
filepath = os.path.join("/Users/keo.sidara/Desktop/Mobile_Test/testcases/regression", "screen_recording_110918-205655.mp4")
warning_message(filepath)
payload = driver.stop_recording_screen()
with open(filepath, "wb") as fd:
fd.write(base64.b64decode(payload))
and i got message
[W3C] Matched W3C error code 'invalid session id' to NoSuchDriverError
[W3C (1530275d)] Encountered internal error running command:
NoSuchDriverError:
Anybody experience with it ? please share me. Thanks
The Appium documentation on the start Recording method is here.
In the AppliumLibrary documentation the source code for keyword Open Application shows that the keyword returns number of the application in the registry.
This means that there is no AppiumLibrary supported way of retrieving the webdriver. This means that a modification to the original library is needed. This has been done already in a fork: nichotined / robotframework-appiumlibrary
Removing the original library from your python installation and installing this one, you then have access to the keyword Get Current Application that returns the driver. Now, you can use the below approach or add another keyword yourself in the same fashion to create the custom Start and Stop Screenrecording.
As I don't have a working Appium Setup, I'm unable to validate this myself:
*** Settings ***
Library AppiumLibrary
*** Test Cases ***
Open Application
... http://localhost:4723/wd/hub
... alias=Myapp1
... platformName=iOS
... platformVersion=7.0
... deviceName='iPhone Simulator'
... app=your.app
${driver} Get Current Application
Call Method ${driver} start_recording_screen
As of robotframework-appiumlibrary v1.5.0.6, support for screen recording has been implemented. Can check https://serhatbolsu.github.io/robotframework-appiumlibrary/AppiumLibrary.html#Start%20Screen%20Recording.
Happy Coding!
I've never used Robot Framework before but I tried a lot of ways to record with the appium driver but I couldn't get it working. The only solution that I found was to use ADB SHELL Commands to record the screen of a device. You should have in mind that not all devices are capable of getting their screen recorded.
adb shell screenrecord /sdcard/test.mp4 --size 480x720 #To start recording
Once you kill the process above you can get the video from the device with these commands
adb pull /sdcard/test.mp4 "C:/"
adb shell rm /sdcard/test.mp4

What would cause InternetExplorerMedium to work on one machine but not another?

I have a VBA script in Access that logs onto a website and downloads some data, I built it using a laptop and use the code of
Dim objIE As InternetExplorerMedium 'special object variable representing the IE browser
Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
Dim element As HTMLLinkElement
Set objIE = New InternetExplorerMedium
On Error GoTo Errorhandler
objIE.Visible = False
DoCmd.Hourglass (True) 'navigate IE to this web page
objIE.navigate www.google.com ' google just for example
Then it inputs the login info into the proper boxes and logs in.
Which works fine, however I installed this front end on another user's PC and it no longer works, it just opens the page but fills in no info.
However, if I change,
Set objIE = New InternetExplorerMedium
to
Set objIE = CreateObject("InternetExplorer.Application")
then it works on their PC. But this change does not work on my laptop.
What would cause this issue and how could I standardize this so I can install on any windows machine without worry of this occurring.
Notes:
We are both on the company LAN, and both are running windows 10 Home.
It was something incredibly simple, I just had to add the website I was accessing as a trusted site in Internet Explorer.

Google assistant sdk on pi do nothing on custom action

I have set up Google Assistant with Raspberry Pi. I'd like to define a custom action, but it's not working. The Google Assistant recognizes the sentence, but does nothing. Here's a log. How do I fix it?
I've edited action.py to put my code
class SwitchControl(object):
"""Control a RC-Socket"""
COMMAND_ON = 'sudo /home/pi/rcswitch-pi/send 00111 3 1'
COMMAND_OFF = 'sudo /home/pi/rcswitch-pi/send 00111 3 0'
def __init__(self, say, toggle):
self.say = say
self.toggle = toggle
def run(self, voice_command):
try:
if (self.toggle == 'ON'):
self.say(_('Turning switch on.'))
for i in range(10):
subprocess.call(SwitchControl.COMMAND_ON, shell=True)
elif (self.toggle =='OFF'):
self.say(_('Turning switch off.'))
for i in range(10):
subprocess.call(SwitchControl.COMMAND_OFF, shell=True)
except (ValueError, subprocess.CalledProcessError):
logging.exception("Error using codesend to toggle rc-socket.") self.say("Sorry I didn't identify that command")
# =========================================
# Makers! Add your own voice commands here.
# =========================================
actor.add_keyword(_('pi power off'), PowerCommand(say, 'shutdown'))
actor.add_keyword(_('pi reboot'), PowerCommand(say, 'reboot'))
actor.add_keyword(_('switch on'), SwitchControl(say, 'ON'))
actor.add_keyword(_('switch off'), SwitchControl(say, 'OFF'))
return actor
Ok finally i manage to make it works :)
First thing you need to know to make local action you need to use cloud speech.
Then i was stuck because in my terminal
when i start google assistant i wasn't seeing :
[2017-07-26 09:25:20,672] INFO:main:ready...
Press the button on GPIO 23 then speak, or press Ctrl+C to quit...
I was only seeing START RECORDING
So i grab an image of pixel raspbian for magpi and it was working with with this distrib and then i have put my old sdcard with my raspbian to retest and tada it was working !!!

Firefox native messaging through webextension

Created a webextension for firefox (currently using Nightly 52), that uses native messaging to launch a java program on Linux (Ubuntu 14, 32x).
The webextension loads, reads the .json file and reads the path which points to a script that starts the java program. The JSON and the path are correct as when I use:
var native = browser.runtime.connectNative("passwordmanager");
console.log("native.name" + native.name); //outputs passwordmanager.
native.onDisconnect.addListener(function(m) { console.log("Disconnected"); });
The above code prints the name of the native port and also prints "Disconnected". So I m guessing the native app is terminating for some reason.
The application is only skeleton right now, that just does sysout and reads sysin and works correctly if Launch it directly through the shell script.
While debugging the webextension, I am not able to step into the call to connectNative, as it just steps-over that call instead of doing step-in. So kind of out of options whats' going wrong.
Please let me know if anyone is able to create a native messaging app based on FF webextension and any pointers on what I might be doing wrong.
Thanks
This solution here shows you how to detect onConnect and onFail. It should help you out to figure out your real problem.
So I don't think you can do proper error handling with connectNative from the JS side alone. You can do somewhat error handling if you get the exe side involved, but you can't get a string for "error reason" when an error occurs. The error is only logged to console.
First make sure to set your deeloper prefs, so messages show in your browser console. You can use this addon - https://addons.mozilla.org/en-US/firefox/addon/devprefs/ - or read that addon description it gives you the MDN page with the prefs to set.
Then this is how you can do some sort of error handling (without error reason) (pseudo-code - i might need a .bind in the callbcks):
function connectNative(aAppName, onConnect, onFail) {
var listener = function(payload) {
if (!connected) {
connected = true;
port.onDisconnect.removeListener(failedConnect);
onConnect();
} else {
// process messages
}
}
var failedConnect = function() {
onFail('failed for unattainable reason - however see browser console as it got logged there');
}
var connected = false;
var port = chrome.runtime.connectNative(aAppName);
port.onMessage.addListener(listener);
port.onDisconnect.addListener(failedConnect);
return port;
}
Now in your exe, as soon as it starts up, make it write to stdout something. That will trigger the onConnect.

Resources