SideeX / sideex-api

SideeX JavaScript API is a JS library running on a webpage for recording and playing web browsing behavior
Apache License 2.0
22 stars 5 forks source link

ReferenceError: window is not defined #1

Closed saravananselvamohan closed 4 years ago

saravananselvamohan commented 4 years ago

I am just trying to use sideex-api in my js file. I added Record & Playback example code in my js file. I tried to run the js file on top of node. It gave me the following error. Can someone help me with this.

I added logs here.

workFolder/node_modules/sideex-api/index.bundle.js:1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SideeX=t():e.SideeX=t()}(window,(function(){return function(e){var t={};function r(o){if(t[o])return t[o].exports;var i=t[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(o,i,function(t){return e[t]}.bind(null,i));return

ReferenceError: window is not defined
    at Object.<anonymous> (workFolder/node_modules/sideex-api/index.bundle.js:1:194)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (workFolder/sidex.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
tyler8812 commented 4 years ago

Window or document is not defined in Node environment, it is only defined in browser. You should try in the browser instead.

saravananselvamohan commented 4 years ago

Thanks so much for your Answer @tyler8812 . So sideex-api code should be placed as chrome/firefox extension. Does it make the context right. Is there any options to run sideex-api as standalone server

tyler8812 commented 4 years ago

@saravananselvamohan No, you don't need to placed in extension. Instead, you can placed in any browser you want. For example, create a HTML file and just load the js file that you write. Then you can start to use sideex-api.

saravananselvamohan commented 4 years ago

Thanks @tyler8812. From your above suggestions I able to understand sideex-api can be able to placed within a webpage removing the constraints of running it in the browser extension. If you able to provide a few samples with placing sideex-api in a demo webpage that would be greatly helpful for the community and also those who starting new to sideex-api like me.

tyler8812 commented 4 years ago

Thanks @saravananselvamohan . Thanks for your suggestion, I'm still writing an introduction about sideex-api, and it will also includes some examples and demos.

saravananselvamohan commented 4 years ago

Hi @tyler8812. I am using this sample HTML file.

<!DOCTYPE html>

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>Spoon-Knife</title>
  <LINK href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>

<img src="forkit.gif" id="octocat" alt="" />

<!-- Feel free to change this text here -->
<p>
  Fork me? Fork you, @octocat!
</p>
<p>
  Sean made a change
</p>

</body>
</html>

I tried many ways to reference sideex-api, but I am struggling to get the appropriate way to use sideex-api

tyler8812 commented 4 years ago

Hi @saravananselvamohan , the HTML file looks fine, but you have to load the js file inside the html,. For example: create a filename.js file

var {SideeX} = require('sideex-api') 
var sideex = new SideeX();

sideex.recorder.start();//start recording
/* 
  Record a command
  For example: click at anywhere on the window,
  then you get a ClickAt command  
*/
sideex.recorder.stop();//stop recording
console.log(sideex.file.command.get(0));//get the first recorded command
sideex.playback.start();//replay the recorded commands

and you have to build the js file, like using browserify: browserify filename.js -o bundle.js after this, inside your HTML, you can just load the js file that you built, type this in the HTML file

<script type="text/javascript" src="bundle.js"></script> //bundle.js is the js file that i built.

You can probably use the sideex-api~~

saravananselvamohan commented 4 years ago

Thanks a ton for the help @tyler8812. I am able to get the events logging in the console. Thank you so much for such patience on helping me.

mustafatalha commented 4 years ago

Hello,

I have similar problem. I know nodejs doesn't have window property but I want to launch a browser from js code (with selenium-webdriver maybe) and record user actions on this launched browser instance.

I saw html solutions above. Is there any other way to launch a browser and record it with sideex?