How to use blockUrls method in chromy

Best JavaScript code snippet using chromy

background.js

Source:background.js Github

copy

Full Screen

1// Copyright 2020 StevenX911. All rights reserved.2// Use of this source code is governed by a MIT license that can be3// found in the LICENSE file.4'use strict';5// 内置默认阻断的URL6let defaultblocklist = [7 "://hm.baidu.com/", // -- 屏蔽某度追踪8 "://www.google-analytics.com/", // -- 屏蔽某歌追踪9 "://www.googletagmanager.com/", // -- 屏蔽某歌追踪10 "://my.openwrite.cn/", // -- 屏蔽某站'阅读更多'11 "://pagead2.googlesyndication.com/", // -- 屏蔽某歌广告12 "://adservice.google.com", // -- 屏蔽某歌广告13 "://csdnimg.cn/release/blogv2/dist/pc/js/detail" // -- 屏蔽某站'阅读更多'14];15const TOSTRING = Function.call.bind(Object.prototype.toString);16chrome.runtime.onInstalled.addListener(function () {17 chrome.storage.sync.get('blockurls', function(data) {18 if(data.blockurls != null && TOSTRING(data.blockurls) === '[object Array]'){19 data.blockurls.forEach(x => {20 if(!defaultblocklist.includes(x)){21 defaultblocklist.push(x);22 }23 });24 console.log('onInstalled: Sync chrome datas successfully!');25 } else {26 chrome.storage.sync.set({27 blockurls: defaultblocklist28 }, function () {29 console.log('onInstalled: Firstly run and init datas.');30 });31 }32 });33});34chrome.runtime.onStartup.addListener(function(){35 chrome.storage.sync.get('blockurls', function(data) {36 if(data.blockurls != null && TOSTRING(data.blockurls) === '[object Array]'){37 data.blockurls.forEach(x => {38 if(!defaultblocklist.includes(x)){39 defaultblocklist.push(x);40 }41 });42 console.log('onStartup: Sync chrome datas successfully!');43 } else {44 chrome.storage.sync.set({45 blockurls: defaultblocklist46 }, function () {47 console.log('onStartup: Firstly run and init datas.');48 });49 }50 });51});52chrome.storage.onChanged.addListener(function(changes, namespace) {53 for (var key in changes) {54 var storageChange = changes[key];55 console.log('Storage key "%s" in namespace "%s" changed. ' +56 'Old value was "%s", new value is "%s".',57 key,58 namespace,59 storageChange.oldValue,60 storageChange.newValue);61 if(TOSTRING(storageChange.newValue) === '[object Array]'){62 defaultblocklist = storageChange.newValue;63 console.log('update defaultblocklist');64 }65 }66});67chrome.webRequest.onBeforeRequest.addListener(68 function (details) {69 if(defaultblocklist.length > 0) {70 for(let item of defaultblocklist){71 if(details.url.indexOf(item) != -1){72 return {73 cancel: true74 };75 }76 }77 }78 // console.log(details.url);79 }, {80 urls: ["*://*/*.js*"]81 },82 ["blocking"]...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

1$(function () {2 const blockUrls = [3 ]45 let changed = true;6 let func = function() {7 if(changed) {8 changed = false;9 10 // Google Search11 $('[data-text-ad="1"]').remove();12 13 // Dummy iframe14 $('iframe:not([src])').remove();15 $('iframe[src="about:blank"]').remove();16 17 for(let url of blockUrls) {18 $('[src*="' + url + '"]').remove();19 $('[style*="' + url + '"]').remove();20 }21 for(let url of blockUrls) {22 $('[href*="' + url + '"] *').css('text-decoration', 'line-through');23 $('[href*="' + url + '"]').css('text-decoration', 'line-through').removeAttr('href');24 }25 }26 };2728 func();29 setInterval(func, 100);3031 let observer = new MutationObserver((mutations) => {32 for(let mutation of mutations) {33 if(mutation.addedNodes) {34 changed = true;35 }36 }37 });38 observer.observe(document.body, {39 childList : true,40 attributes : true,41 characterData: true,42 subtree : true,43 });44 45 46 document.body.addEventListener = function() {}; ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy({ port: 9222 });2chromy.chain()3 .end()4 .then(() => chromy.close())5 .catch((e) => console.log(e));6### new Chromy(options)

Full Screen

Using AI Code Generation

copy

Full Screen

1chromy.chain()2 .end()3 .then(function(result) {4 console.log(result);5 })6 .catch(function(err) {7 console.error('Error: ' + err);8 })9 .then(function() {10 chromy.close();11 });12chromy.chain()13 .end()14 .then(function(result) {15 console.log(result);16 })17 .catch(function(err) {18 console.error('Error: ' + err);19 })20 .then(function() {21 chromy.close();22 });23chromy.chain()24 .clearBlockedUrls()25 .end()26 .then(function(result) {27 console.log(result);28 })29 .catch(function(err) {30 console.error('Error: ' + err);31 })32 .then(function() {33 chromy.close();34 });35chromy.chain()36 .setExtraHttpHeaders({37 })38 .end()39 .then(function(result) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var chromy = require('chromy');2var urls = ["www.google.com","www.facebook.com"];3chromy.blockUrls(urls);4chromy.chain()5 .goto('www.google.com')6 .goto('www.facebook.com')7 .goto('www.yahoo.com')8 .end(function(err, data) {9 console.log('end');10 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var chromy = require('chromy');2chromy.chain()3 .blockUrls(['.*google-analytics.com.*'])4 .evaluate(function() {5 return document.title;6 })7 .end()8 .result(function(result) {9 console.log(result);10 });11var chromy = require('chromy');12chromy.chain()13 .blockRequests(['.*google-analytics.com.*'])14 .evaluate(function() {15 return document.title;16 })17 .end()18 .result(function(result) {19 console.log(result);20 });21var chromy = require('chromy');22chromy.chain()23 .blockUrls(['.*google-analytics.com.*'])24 .unblockUrls(['.*google-analytics.com.*'])25 .evaluate(function() {26 return document.title;27 })28 .end()29 .result(function(result) {30 console.log(result);31 });32var chromy = require('chromy');33chromy.chain()34 .blockRequests(['.*google-analytics.com.*'])35 .unblockRequests(['.*google-analytics.com.*'])36 .evaluate(function() {37 return document.title;38 })39 .end()40 .result(function(result) {41 console.log(result);42 });43var chromy = require('chromy');44chromy.chain()45 .clearCache()46 .evaluate(function() {47 return document.title;48 })49 .end()50 .result(function(result) {51 console.log(result);52 });53var chromy = require('chromy');54chromy.chain()55 .goto('

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy({visible: true});2chromy.chain()3 .wait('body')4 .result(function (result) {5 console.log(result);6 })7 .end()8 .then(function () {9 chromy.close();10 });11[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const Chromy = require('chromy');2const chromy = new Chromy();3chromy.evaluate(() => {4 return document.querySelector('body').innerText;5}).result((v) => {6 console.log(v);7});8chromy.close();9### `new Chromy([options])`

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy();2chromy.chain()3 .blockUrls(['*.google-analytics.com/*'])4 .evaluate(() => {5 })6 .result(result => {7 })8const chromy = new Chromy();9chromy.chain()10 .blockUrlFragments(['google-analytics'])11 .evaluate(() => {12 })13 .result(result => {14 })15const chromy = new Chromy();16chromy.chain()17 .blockUrlRegex([/.*google-analytics.*/])18 .evaluate(() => {19 })20 .result(result => {21 })22const chromy = new Chromy();23chromy.chain()24 .blockUrls(['*.google-analytics.com/*'])

Full Screen

Using AI Code Generation

copy

Full Screen

1chromy.blockUrls(/.*\.css$/, /.*\.js$/, /.*\.woff$/);2chromy.chain()3 .wait(1000)4 .screenshot()5 .end()6 .then(function (result) {7 console.log(result);8 })9 .catch(function (err) {10 console.log(err);11 });

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run chromy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful