Coder Social home page Coder Social logo

phantomjs's Issues

Crashed with phantomjs v2.0/v2.1.1/v2.5beta on Windows7SP1

The only code is here.

package main

import (
	"github.com/benbjohnson/phantomjs"
)

func main() {
	// Start the process once.
	if err := phantomjs.DefaultProcess.Open(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer phantomjs.DefaultProcess.Close()
}

It reports

Fatal Windows exception, code 0xc0000005.
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.

But on macOS, it works well.
Maybe this is related with shim.js?

Not working over SSL

When I make requests over SSL I get an error, I've tried using page.SetSettings but I can't find a setting that ignores SSL errors or something along those lines.

// Works fine, loads the page, etc.
if err := page.Open("http://whatsmyuseragent.org"); err != nil {
    panic(err)
}

// err isn't nil
if err := page.Open("https://google.com"); err != nil {
    panic(err)
}

Stacktrace:

panic: failed

goroutine 1 [running]:
panic(0x624820, 0xc4200e0570)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
main.main()
	/home/gianluca/Desktop/go-test/main.go:42 +0x554

Fix for phantomjs 2.1.1 crash at startup on Windows 10.

I don't have any open source contribution experience,
don't know how to create patch file.
Sorry for inconvenience

Here is fix

func (p *Process) Open() error {
(...)
// Follwing line cause crash.
// cmd.Env = []string{fmt.Sprintf("PORT=%d", p.Port)} // original code

// After slight modification into next line into this one, there is no more crash.
cmd.Env = append(os.Environ(), fmt.Sprintf("PORT=%d", p.Port)) // fixed code
(...)
}

Thank you.

.

Return page source after an element has been created by JS.

I use something like this:

"use strict"

function waitFor(testFx, onReady, timeOutMillis) {
    var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000,
        start = new Date().getTime(),
        condition = false,
        interval = setInterval(function() {
            if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
                condition = (typeof(testFx) === "string" ? eval(testFx) : testFx());
            } else {
                if(!condition) {
                    phantom.exit(1);
                } else {
                    typeof(onReady) === "string" ? eval(onReady) : onReady();
                    clearInterval(interval);
                }
            }
        }, 250);
};

var page = require('webpage').create();

page.open('https://www.somewebsite.com', function(status) {
    if (status !== 'success') {
        console.log('Unable to access network');
    } else {
        waitFor(function() {
	    return page.evaluate(function() {
		var bets = document.getElementsByClassName('someclass').length;
		if (bets < 1) {
		    return false;
		}
		return true;
	    });
        }, function() {
            console.log(page.evaluate(function() {
                return document.documentElement.innerHTML;
            }))
        }, 20000);
    }
});

What is the better way to do something like this with this package?

Thanks for your help.

Evaluate function()

Is it possible to return a group of css selectors from this function then pass it back into another Evaluate function later on ? Or an equivalent workaround ? Thank you.

Evaluate() vs EvaluateJavaScript()

What are the differences between Evaluate() and EvaluateJavaScript() aside from the name of the functions and the comment descriptions, they appear to be the same thing. What am I missing ? Thank you Ben.

// EvaluateJavaScript executes a JavaScript function.
// Returns the value returned by the function.
func (p *WebPage) EvaluateJavaScript(script string) (interface{}, error) {
	var resp struct {
		ReturnValue interface{} `json:"returnValue"`
	}
	if err := p.ref.process.doJSON("POST", "/webpage/EvaluateJavaScript", map[string]interface{}{"ref": p.ref.id, "script": script}, &resp); err != nil {
		return nil, err
	}
	return resp.ReturnValue, nil
}

// Evaluate executes a JavaScript function in the context of the web page.
// Returns the value returned by the function.
func (p *WebPage) Evaluate(script string) (interface{}, error) {
	var resp struct {
		ReturnValue interface{} `json:"returnValue"`
	}
	if err := p.ref.process.doJSON("POST", "/webpage/Evaluate", map[string]interface{}{"ref": p.ref.id, "script": script}, &resp); err != nil {
		return nil, err
	}
	return resp.ReturnValue, nil
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.