Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: useProxyPer[target.constructor.name] is not a function #105

Open
io-store opened this issue Mar 10, 2024 · 2 comments
Open

TypeError: useProxyPer[target.constructor.name] is not a function #105

io-store opened this issue Mar 10, 2024 · 2 comments

Comments

@io-store
Copy link

io-store commented Mar 10, 2024

When I use the useProxy function I get this error:

  • TypeError: useProxyPer[target.constructor.name] is not a function

code:
const puppeteer = require('puppeteer');
const useProxy = require('puppeteer-page-proxy');
(async () => {
var proxy = "ip:port:username:password".split(":");
proxy = 'http://'+proxy[2]+':'+proxy[3]+'@'+proxy[0]+':'+proxy[1];
const browser = await puppeteer.launch({
args: ['--disable-web-security'],
executablePath:"C:\Program Files\Google\Chrome\Application\chrome.exe",
headless:false,
});
const page = await browser.newPage();
await useProxy(page, proxy);
await page.goto('https://www.google.com/search?q=what+is+my+ip+address');
await new Promise(reslove => setTimeout(reslove,1000));
await browser.close();
})();
i want help please

NodeJS Version: 20.9.0
npm Version: 10.1.0
package version: 1.3.0

  • Note
    • i used @lem0-packages/puppeteer-page-proxy also but showing me that
    | TypeError: Cannot read properties of undefined (reading 'get')
@PineTang
Copy link

When I use the useProxy function I get this error:

  • TypeError: useProxyPer[target.constructor.name] is not a function

code: const puppeteer = require('puppeteer'); const useProxy = require('puppeteer-page-proxy'); (async () => { var proxy = "ip:port:username:password".split(":"); proxy = 'http://'+proxy[2]+':'+proxy[3]+'@'+proxy[0]+':'+proxy[1]; const browser = await puppeteer.launch({ args: ['--disable-web-security'], executablePath:"C:\Program Files\Google\Chrome\Application\chrome.exe", headless:false, }); const page = await browser.newPage(); await useProxy(page, proxy); await page.goto('https://www.google.com/search?q=what+is+my+ip+address'); await new Promise(reslove => setTimeout(reslove,1000)); await browser.close(); })(); i want help please

NodeJS Version: 20.9.0 npm Version: 10.1.0 package version: 1.3.0

  • Note
    • i used @lem0-packages/puppeteer-page-proxy also but showing me that
    | TypeError: Cannot read properties of undefined (reading 'get')

You can create a CdpHTTPRequest in useProxyPer with the same code as HTTPRequest

const useProxyPer = {
...
CdpHTTPRequest: async (request, data) => {
      let proxy, overrides;
      // Separate proxy and overrides
      if (type(data) === "object") {
          if (Object.keys(data).length !== 0) {
              proxy = data.proxy;
              delete data.proxy;
              overrides = data;
          }
      } else {proxy = data}
      // Skip request if proxy omitted
      if (proxy) {await requestHandler(request, proxy, overrides)}
      else {request.continue(overrides)}
  }
...
}

@smeltH
Copy link

smeltH commented Dec 5, 2024

也可以试一下这个方法
Object.defineProperty(request.constructor, 'name', { value: 'HTTPRequest', });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants