Browser.pkcs11 undefined


(Stevennobile) #1

Greetings. I am trying to create a web extension that will determine if there is a card in the card reader. I have a simple extension set up to just test run. When I run the web page I am getting browser.pkcs11 undefined. I have a PKCS11 Module created in my firefox call “TAA ActivClient Module”. Any help would be greatly appreciated.

Here is my simple manifest.json
{

  "manifest_version": 2,
  "name": "CACListener",
  "version": "1.0",

  "description": "Adds a polling Listener to the carder reader slot",

  "icons": 
  {
    "48": "icons/border-48.png"
  },
"permissions": 
	[
	"pkcs11"
	],
	
  "content_scripts": 
  [
    {
     	"matches": ["*://*/taa/*"],
      	"js": ["CACListener.js"]
    }
  ]
}

Here is the code that is failing:

try
	{
	if (!navigator.appName.toUpperCase().substring(0, 9) == "MICROSOFT");
	{	
		<b>var getting = browser.pkcs11.getModuleSlots("TAA ActivClient Module");</b>
		alert(lastStatus);
		if(lastStatus != currentStatus)
		{
			(currentStatus.equalsIgnoreCase("Inserted") ? onSmartCardInsert() : onSmartCardRemove() );
		}
					
		setTimeout(checkReaderStatus, 1000);
	}
	alert("2");
	}
	catch(e)
	{
		alert(e);
	}

(Martin Giger) #2

Is the code that’s failing in the content script? Because I don’t see a background script or similar declared. If yes, you’ll have to move that bit of code to the background or similar. See also https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#WebExtension_APIs

Further, code posted on here is much more readable if wrapped in a code block (the </> button, or ``` markdown code blocks).


(Stevennobile) #3

OK - So I can’t access the pkcs11 api from a content_script but I can from a backgroud script. Got that. No I need to play around with a combination with messaging.

Thanks