Skip to content

Commit

Permalink
Merge pull request #7 from jpchip/remove-headless-mode
Browse files Browse the repository at this point in the history
remove headless mode
  • Loading branch information
jpchip authored Dec 4, 2018
2 parents de95236 + 09d8e62 commit dda69e0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
AMAZON_USERNAME=[email protected]
AMAZON_PASSWORD=123456
HEADLESS=1
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.2.0 - 2018-12-04
### Fixed
- Took out ability to run headless, as it doesn't work
- Add error handler in case box click fails

## 0.1.1 - 2018-12-04
### Fixed
- Start on First Page
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,3 @@ Copy .env.example to .env, adding your own Amazon username and password.
$ npm install
$ npm start
```

Check the console to see how things are going.

To run in browser, change `HEADLESS=1` in .env file to `HEADLESS=0`.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ async function enterGiveaways(page, pageNumber) {
console.log('waiting for box...');
await page.waitForSelector('#box_click_target');
await page.click('#box_click_target', {delay: 2000});
const resultTextEl = await page.waitForSelector('.qa-giveaway-result-text');
const resultText = await page.evaluate(resultTextEl => resultTextEl.textContent, resultTextEl);
console.log(resultText);
try{
const resultTextEl = await page.waitForSelector('.qa-giveaway-result-text');
const resultText = await page.evaluate(resultTextEl => resultTextEl.textContent, resultTextEl);
console.log(resultText);
} catch(error) {
console.log('could not get result, oh well. Moving on!');
}

await navigateBackToGiveaways(page);
} else {
Expand Down Expand Up @@ -101,8 +105,7 @@ async function signIn(page, username, password) {

//start index code
(async () => {
const headless = (process.env.HEADLESS === 1);
const browser = await puppeteer.launch({headless: headless});
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();

//sign in
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "giveaway-grabber",
"version": "0.1.1",
"version": "0.2.0",
"description": "Automates entries for Amazon Giveaways",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit dda69e0

Please sign in to comment.