Skip to content

Instantly share code, notes, and snippets.

View codesorter2015's full-sized avatar
🏠
Working from home

Krish codesorter2015

🏠
Working from home
View GitHub Profile
@codesorter2015
codesorter2015 / puppeteer_pdf.js
Created December 27, 2019 09:27
Grab pdf content using puppeteer
const fse = require('fs-extra');
const puppeteer = require('puppeteer');
const getPdf = (page) => {
let url = await page.url();
return page.evaluate(url => {
return new Promise(async resolve => {
const reader = new FileReader();
const response = await window.fetch(url, {
credentials: 'same-origin',
method: 'POST'
@codesorter2015
codesorter2015 / index.js
Created November 6, 2019 05:12
Add script via page.addScriptTag (puppeteer)
const puppeteer = require('puppeteer');
(async () => {
try {
const browser = await puppeteer.launch({
headless: false,
})
const page = await browser.newPage();
await page.setBypassCSP(true);
await page.goto('https://github.com/google');
await page.addScriptTag({
@codesorter2015
codesorter2015 / IEF.js
Created November 2, 2019 04:13
Example of IEF (Immediately Executing Function) in node
/*Immediately Executing Function:
You can execute a function immediately after you define it.
Simply wrap the function in parentheses () and invoke it
The reason for having an IEF is to create a new variable scope.
Example:
--------
*/
(function test() { console.log('test was executed!'); })();
@codesorter2015
codesorter2015 / skipAds.js
Created August 23, 2019 06:46
How to automatically skip youtube Ads using puppeteer?
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();
let url = 'youtube url';
await page.goto(url);
await page.evaluate(() => {
self.moHandler = {
changesObserver: function (mutation) {
if (mutation.type === 'attributes'){
@codesorter2015
codesorter2015 / loadScript.js
Created August 13, 2019 09:16
Load Script Using Java Script
function loadScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
@codesorter2015
codesorter2015 / Proxy Window Object
Created August 12, 2019 11:46
Create a proxy window object using javascript
handler = {
get: function(target, property, receiver) {
let targetObj = target[property];
if(typeof targetObj == "function") {
return (...args) => target[property].apply(target,args)
} else {
return targetObj;
}
}
}
@codesorter2015
codesorter2015 / reloadpage.txt
Last active March 9, 2022 12:24
reload the page using javascript
location = location
... and a 534 other ways to reload the page with JavaScript
location = location
location = location.href
location = window.location
location = self.location
location = window.location.href
location = self.location.href
location = location['href']
location = window['location']
const puppeteer = require('puppeteer');
const proxyChain = require('proxy-chain');
(async() => {
const oldProxyUrl = 'http://bob:password123@proxy.example.com:8000';
const newProxyUrl = await proxyChain.anonymizeProxy(oldProxyUrl);
// Prints something like "http://127.0.0.1:45678"
console.log(newProxyUrl);
ProxyRequests Off
ProxyPreserveHost On
<Proxy pos.##REDACTED###.za>
Order deny,allow
Allow from all
</Proxy>
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteRule /(.*) ws://localhost:8080/$1 [P,L]
ProxyPass /socket.io http://localhost:8080/socket.io/ retry=0 timeout=5
@codesorter2015
codesorter2015 / gist:d7fe61072403a46e289b1ee0393dd0a1
Created May 28, 2019 09:49
Apache Proxy With Socket Setup
<VirtualHost *:80>
ServerName test.localhost
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteRule /(.*) ws://localhost:3001/$1 [P,L]