Topics

How to run javascript code from NVDA addon?

vimuths@...
 

Hi I have created a NVDA addon for firefox. So I have firefox.py python file. For that I need to run a simple js code.

import appModuleHandler
import ui
import api

class AppModule(appModuleHandler.AppModule):

    def script_sayHello(self, gesture):
        js = 'alert()'

    __gestures={
        "kb:a":"sayHello"
    }

is there a way to run this js?. To understand easily I added simple alert inside js variable. The code is from python.

Andy B.
 

Hi,

 

I would think this would be a security hazard. If there is no specific need to run JavaScript from a Python backend, don’t do it. There are better methods to access web elements through Python. What exactly does this add-on do? I have an add-on (Developer toolkit) that helps blind/VI developers create user interfaces and web content without sighted assistance.

 

 

From: vimuths via Groups.Io
Sent: Tuesday, July 23, 2019 6:49 AM
To: nvda-devel@groups.io
Subject: [nvda-devel] How to run javascript code from NVDA addon?

 

Hi I have created a NVDA addon for firefox. So I have firefox.py python file. For that I need to run a simple js code.

import appModuleHandler
import ui
import api
 
class AppModule(appModuleHandler.AppModule):
 
    def script_sayHello(self, gesture):
        js = 'alert()'
 
    __gestures={
        "kb:a":"sayHello"
    }

is there a way to run this js?. To understand easily I added simple alert inside js variable. The code is from python.

 

vimuths@...
 

I need to access some contents of some sites...

For example I have this code,

import appModuleHandler
import ui
import api

class AppModule(appModuleHandler.AppModule):
   
    def script_sayHello(self, gesture):
        obj = api.getNavigatorObject()
        ui.browseableMessage(obj.name, isHtml=False)

    __gestures={
        "kb:a":"sayHello"
    }

But when I try to read this,

<span class=" pdp-price pdp-price_type_normal pdp-price_color_orange pdp-price_size_xl" data-spm-anchor-id="a2a0e.pdp.0.i0.2ea54a35OvuCpq">Rs. 269</span>

I get none as obj.name.

Is there a way I can access the html of this and added to a python variable?

Andy B.
 

You can by grabbing api.getFocusObject() and manipulating it that way. However, grabbing and manipulating html elements is tricky at best. <span> elements have the isFocusable flag set to False. This is why api.getNavigatorObject() results in None. The only thing I can think of is to walk down the treeInterceptor object of elements until you find the object you are looking for. You could look at the IA2Attributes object for a specific tag such as span, or a specific attribute such as class or id, but you can’t be sure the IA2Attributes will remain consistent, or have the attribute you are looking for. In fact, my project makes extensive use of html elements, and I found an element with no IA2Attributes. Go figure. I wish I could offer you more than this, but the web is not static, and developers aren’t required to follow standards of any kind.

 

 

From: vimuths via Groups.Io
Sent: Tuesday, July 23, 2019 7:40 AM
To: nvda-devel@groups.io
Subject: Re: [nvda-devel] How to run javascript code from NVDA addon?

 

I need to access some contents of some sites...

For example I have this code,

import appModuleHandler
import ui
import api

class AppModule(appModuleHandler.AppModule):
   
    def script_sayHello(self, gesture):
        obj = api.getNavigatorObject()
        ui.browseableMessage(obj.name, isHtml=False)

    __gestures={
        "kb:a":"sayHello"
    }

But when I try to read this,

<span class=" pdp-price pdp-price_type_normal pdp-price_color_orange pdp-price_size_xl" data-spm-anchor-id="a2a0e.pdp.0.i0.2ea54a35OvuCpq">Rs. 269</span>

I get none as obj.name.

Is there a way I can access the html of this and added to a python variable?

 

vimuths@...
 

So I think the js option is the better solution. Is there a way to run a js code in python or any other solution?

James Scholes
 

If you want to modify a web page to be more accessible, you should develop either a userscript or a browser extension. These run within the context of the browser itself, and are clear about their security limitations and responsibilities. You cannot reach over directly from NVDA to the web browser and run arbitrary code in it.

Regards,

James Scholes

On 23/07/2019 at 1:17 pm, vimuths via Groups.Io wrote:
So I think the js option is the better solution. Is there a way to run a js code in python or any other solution?