# How to grab Network data from DevTools using BrowserLibray

**URL:** <https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381>\
**Category:** Browser\
**Created:** [2 March 2023 10:13 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381 "2023-03-02T10:13:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![syankovsky](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@syankovsky](https://forum.robotframework.org/u/syankovsky)\
**Post date:** [2 March 2023 10:13 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381/1 "2023-03-02T10:13:42Z")

</div>

Hey everyone,

I’m trying to set up my tests so that they get logs from the Console and Network tabs in DevTools and save them in the log file after execution, when they are failed. I used “Get Console Log” in order to grab Console logs, and it works perfect! Could you help me with grabbing Network data from DevTools, please, can I do it using BrowserLibrary right now?

---

<div class="post-metadata">

**Author:** ![shiwopotato](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/shiwopotato/32/3898_2.png) [@shiwopotato](https://forum.robotframework.org/u/shiwopotato)\
**Post date:** [10 July 2024 01:22 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381/2 "2024-07-10T01:22:32Z")

</div>

Hi! Did you manage to find a solution? 🙂

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [10 July 2024 07:11 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381/3 "2024-07-10T07:11:25Z")

</div>

[https://marketsquare.github.io/robotframework-browser/Browser.html#New%20Context](https://marketsquare.github.io/robotframework-browser/Browser.html#New%20Context)

there’s option called `recordHar`. Its not exactly the same has getting the browser network log _but_ it should contain all the information regarding what sort of requests where done while the context was open.

---

<div class="post-metadata">

**Author:** ![shiwopotato](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/shiwopotato/32/3898_2.png) [@shiwopotato](https://forum.robotframework.org/u/shiwopotato)\
**Post date:** [12 July 2024 05:22 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381/4 "2024-07-12T05:22:35Z")

</div>

Thank you! I’m able to get the Network Data. However, I also want to parse it during runtime is there a way to do it? I observed that we could only get the updated har after the context is close.

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [12 July 2024 07:33 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381/5 "2024-07-12T07:33:36Z")

</div>

> However, I also want to parse it during runtime is there a way to do it?

Thats the reason why i mentioned “its not exactly the same” as there’s the requirement to close the context before the har is available.

In playwright itself, [Request | Playwright](https://playwright.dev/docs/api/class-request) api does provide a way to catch both requests and responses that could be used. However, there is no “clean way” to integrate those in rf side … Not impossible to a bit cumbersome and would definitely need someone who knows how to write javascript.

My initial approach would be to add javascript code as `jsextension` (see importing section in the keyword docs) that adds 1 keyword for monitoring `request` and `response` events and when those happens, store the objects as json either into memory within the extension itself _or_ to json file. And then another keyword that that returns the data to robot framework side. If you would store the req and resp objects into a file, obviously the second keyword wouldn’t need to be written in the same jsextension file and/or in javascript…

As a side note - ping @aaltat. Would it be big effort to get request callbacks back to RF side ? My guess would be, it would 😉

---

<div class="post-metadata">

**Author:** ![shiwopotato](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/shiwopotato/32/3898_2.png) [@shiwopotato](https://forum.robotframework.org/u/shiwopotato)\
**Post date:** [30 July 2024 00:03 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381/6 "2024-07-30T00:03:11Z")

</div>

Thank you so much, I will try this 🙂

---

<div class="post-metadata">

**Author:** ![shiwopotato](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/shiwopotato/32/3898_2.png) [@shiwopotato](https://forum.robotframework.org/u/shiwopotato)\
**Post date:** [31 July 2024 01:29 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381/7 "2024-07-31T01:29:08Z")

</div>

As I read the Browser documentation, I found out that the library already supported `request` and `response` events through [Wait for Response](https://marketsquare.github.io/robotframework-browser/Browser.html#Wait%20For%20Response) and [Wait for Request](https://marketsquare.github.io/robotframework-browser/Browser.html#Wait%20For%20Request). 🙂

---

<div class="post-metadata">

**Author:** ![ollie-zhang](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ollie-zhang/32/4448_2.png) [@ollie-zhang](https://forum.robotframework.org/u/ollie-zhang)\
**Post date:** [13 January 2025 08:22 UTC](https://forum.robotframework.org/t/how-to-grab-network-data-from-devtools-using-browserlibray/5381/8 "2025-01-13T08:22:41Z")

</div>

from robot.libraries.BuiltIn import BuiltIn

def get\_capcha():  
driver = BuiltIn().get\_library\_instance(‘SeleniumLibrary’).driver

```
logs = driver.get_log("performance")
for log in logs:
    log_message = json.loads(log["message"])  
    # print(log_message)
    message = log_message["message"]
    if message["method"] == "Network.responseReceived":

```

…

thanks for your share! I used to get the network data by this python func
