octaltree / playwright-rust

Playwright port to Rust
311 stars 35 forks source link

serialize_argument, parse_result #4

Closed octaltree closed 3 years ago

octaltree commented 3 years ago

serialize/deserialize "d"

from playwright.sync_api import sync_playwright
import time

with sync_playwright() as p:
    b = p.chromium.launch(headless=True)
    c = b.new_context()
    p = c.new_page()
    s = p.evaluate("() => { let a = Date.now(); return {'datetime': a}; }")
    print(s)

# Returns 'n', not 'd'
# RECV> {
#   "id": 4,
#   "result": {
#     "value": {
#       "o": [
#         {
#           "k": "datetime",
#           "v": {
#             "n": 1615732089099
#           }
#         }
#       ]
#     }
#   }
# }
# {'datetime': 1615732089099}
from playwright.sync_api import sync_playwright
import time
import datetime

with sync_playwright() as p:
    b = p.chromium.launch(headless=True)
    c = b.new_context()
    p = c.new_page()
    d = datetime.datetime.now()
    s = p.evaluate("d => { return {'datetime': d}; }", d)
    print(s)
# SEND> {
#   "id": 4,
#   "guid": "Frame@96fe6bd2c95c4d8e2118b2355db57207",
#   "method": "evaluateExpression",
#   "params": {
#     "expression": "d => { return {'datetime': d}; }",
#     "arg": {
#       "value": {
#         "d": "2021-03-15T00:01:34.956666Z"
#       },
#       "handles": []
#     }
#   },
#   "metadata": {
#     "stack": [
#       {
#         "file": "/home/octaltree/workspace/pw/main.py",
#         "line": 10,
#         "function": "<module>"
#       }
#     ],
#     "apiName": "page.evaluate"
#   }
# }
# RECV> {
#   "id": 4,
#   "result": {
#     "value": {
#       "o": [
#         {
#           "k": "datetime",
#           "v": {
#             "d": "2021-03-15T00:01:34.956Z"
#           }
#         }
#       ]
#     }
#   }
# }
# {'datetime': datetime.datetime(2021, 3, 15, 0, 1, 34, 956000)}