Error encountered: Circular reference issue was encountered when attempting to retrieve navigator.plugins with the use of Selenium and Python

I'm attempting to access the value of navigator.plugins from a Selenium-driven ChromeDriver initiated Browsing Context.

Using , I am able to retrieve navigator.userAgent and navigator.plugins as shown below:

https://i.sstatic.net/J7NQ3.png

However, when using Selenium's execute_script() method, I can extract the navigator.userAgent successfully, but trying to access navigator.plugins results in a circular reference error:

  • Code Block:

    from selenium import webdriver 
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get("https://www.google.com/")
    print("userAgent: "+driver.execute_script("return navigator.userAgent;"))
    print("plugins: "+driver.execute_script("return navigator.plugins;"))
    
  • Console Output:

    userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
    Traceback (most recent call last):
      File "C:\Users\Soma Bhattacharjee\Desktop\Debanjan\PyPrograms\navigator_properties.py", line 19, in <module>
        print("vendor: "+driver.execute_script("return navigator.plugins;"))
      File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 636, in execute_script
        'args': converted_args})['value']
      File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
        self.error_handler.check_response(response)
      File "C:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.JavascriptException: Message: javascript error: circular reference
      (Session info: chrome=83.0.4103.116)
    

I have read about dealing with circular reference errors, but I am uncertain about how to resolve it in this particular context.

  • Example of a circular reference in Javascript?
  • Detecting and fixing circular references in JavaScript
  • Is circular reference between objects a bad practice?

Could someone assist me in retrieving the value of navigator.plugins please?

Answer №1

When extracting non-primitive data structures from a browser realm, there may arise a serialization glitch. Upon examination of the structure of a single plugin, it becomes evident that it possesses a recursive nature which poses challenges for the serializer. https://i.sstatic.net/MJzr3.png

If you require a list of plugins, consider returning a serialized string separated by newlines and then splitting it using a newline character in the Python realm.

Here is an example:

plugins = driver.execute_script("return Array.from(navigator.plugins).map(({name}) => name).join('\n');").split('\n')

Answer №2

I believe the reason for this behavior is related to how navigator.plugins returns a collection known as a PluginArray.

The documentation for the PluginArray provides details about its methods and properties, which helped me create a script that generates a list of plugin names. Feel free to modify it according to your requirements.

print("List of plugins: " + driver.execute_script("var names = []; for(var i = 0; i < navigator.plugins.length; i++) { names.push(navigator.plugins[i].name); }; return names.join();"))

Answer №3

Circular Dependencies

When two separate objects pass references to each other, it results in circular dependencies. This type of referencing indicates a strong coupling between the objects, where changes made to one object may require adjustments in the other object as well.


NavigatorPlugins.plugins

The NavigatorPlugins.plugins function retrieves a list of installed plugins in the application through a PluginArray object. This object contains information about the various plugins and allows access to them using methods like item(index) or namedItem("name").


To extract properties from navigator.plugins, you can use the following code snippets:

  • To retrieve the list of names of the plugins:

    print(driver.execute_script("return Array.from(navigator.plugins).map(({name}) => name);"))
    
    • Console Output:

      ['Chrome PDF Plugin', 'Chrome PDF Viewer', 'Native Client']
      
  • To fetch the list of filenames of the plugins:

    print(driver.execute_script("return Array.from(navigator.plugins).map(({filename}) => filename);"))
    
    • Console Output:

      ['internal-pdf-viewer', 'mhjfbmdgcfjbbpaeojofohoefgiehjai', 'internal-nacl-plugin']
      
  • To obtain the list of descriptions of the plugins:

    print(driver.execute_script("return Array.from(navigator.plugins).map(({description}) => description);"))
    
    • Console Output:

      ['Portable Document Format', '', '']
      

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Copy and paste the code from your clipboard into various input fields

I have been searching for a Vanilla JavaScript solution to copy and paste code into multiple input fields. Although I have found solutions on the internet, they are all jQuery-based. Here is an example of such a jQuery solution <input type="text" maxl ...

Deploying tracking scripts within GTM containers during Turbolinks transitions

Is there a solution for getting a Google Tag Manager container to fire all its tags under Turbolinks? In my Rails 4.0 application with Turbolinks, I have included the following code in a footer that is rendered on every page within the <head> tags: ...

I'm encountering an error when trying to pass multiple parameters in an AJAX request

I am trying to pass three parameters to my ajax code. Here is the snippet of my code: $(document).ready(function () { SearchText(); }); function SearchText() { $("#txt712").autocomplete({ source: function (request, resp ...

Analyzing and inserting elements into an array of objects

The following code aims to: 1) iterate through the two arrays, 2) if an item exists in both arrays, add its value to the value of the matching item in the first array, 3) if the item is found in arr2 but not in arr1, add the item to arr1. The code funct ...

Adjust the size of the wrapper/mask as the browser is resized

Is there a way to adjust the size of my wrapper and mask when the browser is resized? Currently, the mask stops once it's loaded, causing the content to be cut off when scrolling. You can view an example on this site. $(document).ready(function() { ...

When the tooltip component is triggered in a React application, the cursor is automatically directed to

I have been working on creating an input field that allows users to enter time as input. Here's the code snippet I am using: <InputMask mask="99:99" onBlur={handleOnBlur} onChange={(e) => { const ...

Encountering a React error when attempting to generate a URL for an image in Sanity

Server Error Error: The asset reference 'e173af30-fd2d-42ed-a364-d92a2cddf32c' is malformed. It should be in the format of an id such as "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg".https://i.stack.imgur.com/koC26.png https://i.stack.imgur.com/ ...

What is the method for adding/removing the 'hidden' attribute within a <p hidden> element

What is the best way to toggle the visibility of 'hidden' in the element <p hidden>My Text</p>? I attempted removing the attribute and setting it to false, but unfortunately, neither method seemed to work. let paragraphElements = d ...

Remove the hyphen from a user input field using Angular 2 and reactive forms

After deleting data from input fields, I am facing an issue where the dynamic addition of a hyphen prevents the input field from being cleared. Is there a solution to this problem? How can I delete or clear the input fields effectively? Although I have ad ...

What is the best way to input keys into the currently selected element?

During my experimentation, I discovered that several modals and dropdowns in my tests open with their input boxes automatically focused. I found a way to verify if an element is in focus, but I'm wondering if there's a quicker method to input ke ...

The ASPX validation will not be able to access the .js file

I am facing an issue with client-side validation using JavaScript (.js). Despite linking the path in the head section, the ASP file doesn't seem to reach the JavaScript file. <head runat="server"> <meta http-equiv="Content-Type" content="tex ...

Ways to assign values to an array within an object

I'm attempting to transfer the contents of one array into an array within an object, but I keep encountering this error: Type 'any[]' is not assignable to type '[]'. Target allows only 0 element(s) but source may have more. Here ...

Struggling to properly line up the baselines of navigation list items that are styled as circular elements using CSS

I have transformed my navigation menu into a series of CSS circles with text inside. The issue I am facing is that the text spills out unevenly based on the amount of content in each circle. To address this, I used a JavaScript solution to center-align the ...

What are some tips for creating an improved React list container component?

I have a small application that fetches movie data. The component hierarchy is not very complex. The state is stored in App.js and then passed down to the Movies.js component, which simply displays a list of movies in a ul element. Data passing from App.j ...

Automate Website Testing - Take Screenshots with Robot to Capture URLs

Robot robot = new Robot(); BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); ImageIO.write(screenShot, "JPG", new File("ScreenShot.jpg")); This snippet captures the desktop screen when test ...

How to Determine if Your Chrome Packaged App is Operating in Kiosk Mode

I'm in the process of developing an application that is able to function both in kiosk mode and regular mode (such as opening from a Chrome browser). However, I need certain features to be restricted to kiosk mode only. How can I determine if the appl ...

Having difficulty retrieving items from Mongoose-Node database

I am currently working with a Mongodb database that stores resume objects. These objects contain various skills information and I have set up a node-express server to query the database based on specific skills. For example, when querying for a skill like ...

The current export script is experiencing difficulties when working with the next/image component

I am working on a project that I need to build and export, but I am facing an error during the process. Below is the build script found in my package.json file: "scripts": { "build": "next build && next export" } ...

Transforming data from a JSON format into a JavaScript array

I'm trying to convert a JSON string into an array containing the values from the JSON. When I use json.stringify(jsonmybe) and alert it, I see [{"role":"noi_user"},{"role":"bert_user"}] (which is in JSON format). My goal is to extract `noi_user` and ` ...

Securing access across multiple routes in a React application

I am facing a challenge in my React app where I need to verify the logged-in state before allowing access to multiple routes. Despite consulting various resources like Stack Overflow for solutions such as creating a Private Route, I have only found example ...