Self Explore part 3: Integrate electron with Playwright

Royer Adames
6 min readMar 16, 2021

eslint errors

Got errors by running

"lint": "eslint .",

New script


"lint:fix": "eslint . --fix",

Better yet,Ignore the script

Then it allows you to be able to save it on the repo.

Start playwright script when you click a button.

document.querySelector(".navbar__search-input").value = "yes"

can add text to an input value

Error

Module parse failed: Unexpected character '�' (1:2)
src/node_modules/playwright/bin/PrintDeps.exe
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Add this loader to your webpack config

{
test: /\.exe$/i,
use: 'raw-loader',
},

Error: cookies are not login in user

Facebook cookies on Austin login chromium-browser

the error was that there was no storageState being set

Things to do

  • test and develop playwright on the project app
  • fix/update download path to be relative to the app project
  • develop Twitter script
  • Setup the website

I could do something with this

How to handle these errors

A great resource on how to deal with directories

error

Solution

After lots of logins

Solution:

Turn off the VPN and log in.

Focus on refactoring, capturing user credentials

  • log in to Facebook on electron
  • save credentials on env variable or file
  • don't ask them to login in if they have their credential files on the app
  • allow them to delete their credential file

How to write a file?

fs = require('fs');
fs.writeFile(filename, data, [encoding], [callback])

You need to stringify the data, but will be saved the actual data has Javascript code.

Give the option to save user credentials files.

Does it need to be encrypted?

No. It’s already is.

Saving the credentials breaks the reenter password solution

How to check if a file exists?

import { existsSync } from 'fs';

if (existsSync('/etc/passwd'))
console.log('The path exists.');

path.normalize(path)?

App so far

How to handle the credential file?

What about if the app is running, the user cannot delete it.

For now, have them on the project file.

Debug script

Dynamic Imports

In situations where you wish to load a module conditionally or on-demand, you can use a dynamic import instead

let module = await import('/modules/my-module.js');

Import only takes string literal.

It accepts absolute and relative paths.

node fs read may be a better solution for what I am trying to do.

You get a string of all the text inside that file.

  • only store the text of the cookies
  • take away all of the Javascript syntax

Undefined vs. Null

The compiler sets undefined, and the programmer sets null.

Request vs. Response

Facebook cookies that sign in users

c_user

xs

Has long as you have both up today cookies, you can sign in.

Fail attend to capture id and pass

Too many responses and requests going, though. I need the specific one that activates when the login button is clicked on.

How can I know when the cookies are set?

I could check from playwright if the cookies are set

or I can check a specific cookie through the dev tools

document.cookie

Destructuring assignment

Need a way to validate the cookies

Does refreshing keep it on the same tab? no

Script broke: operation not permitted.

How to avoid this?

  • Check before running the script if there is a zip file. If so, unzip it delete it, and close the script.
  • all scripted files need to be deleted, or they can be rename and unzip
  • The immediate solution I can think of it’s only to have the unzip files save on the user document folder. We will have to think about having user permission to handle their document files.

Wrapping things up

--

--