Skip to main content

Automatically Open DevTools when newtab open in Browser

One of cool topic which is told by my friend, He is web developer we want devtools to open whenever new tab get open so we searched the internet to automatically open devtools there are plenty but none didn't work for me

So I decided to write by own using some browser addon i have

Here the procedure is for MAC

Tools:
      [+] GreaseMonkey -> available for firefox
      [+] TamperMonkey -> incase of chrome

Working:

I achieved this using Client-Server Model

Client : Browser using the GreaseMonkey/TamperMonkey send the request to the Server

Server: If any request received from client, It send the KeyStroke option+command+c ( differs for Operating system )  so the devtools will open


Program:

Client Side
========

// ==UserScript==
// @name     Unnamed Script 977967
// @version  1
// @grant    none
// @require  https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js
// @include  *
// ==/UserScript==

var socket = io.connect('http://localhost:9999');

  socket.on('news', function (data) {
    console.log(data);
    /*socket.emit('my other event', { my: 'data' });*/
 });


Install this script in greaseMonkey or TamperMonkey and you are good to go

Server Side
========

Here i used python because i like it very much beside you can create server in any language such as nodeJs,Ruby or whatever language you like

import SocketServer
import os

class MyTCPHandler(SocketServer.BaseRequestHandler):

    def handle(self):
        cmd = """
        osascript -e 'tell application "System Events" to keystroke "c" using {option down,command down}'
        """
        os.system(cmd)
        self.data = self.request.recv(1024).strip()
        print "{} wrote:".format(self.client_address[0])
        print self.data
        self.request.sendall(self.data.upper())

if __name__ == "__main__":
    HOST, PORT = "localhost", 9999
    server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
    server.serve_forever()


here osascript application is used to send keystoke but if you are using other Operating System
Windows - check how to send keystroke through cmd and paste there instead of osascript
Linux - You are in luck check out my previous blog post i described how to send keystroke from python


Ya this is Fun and Awesome
hope every one try it

If any problem occur, Comment down below

If you have any crazy idea like this ping me up , i will be glad to help you























   


Comments

  1. Hey can you tell me how to initialise the server side?
    Would I have to run the server every time manually?

    ReplyDelete
    Replies
    1. Yes the server need to start manually by us
      wait for next post , i will tell you how to run the server in background in linux
      keep coding , have fun

      Delete

Post a Comment

Popular posts from this blog

C program jackpot

/*Program to show sum of 10 elements of array & show the average.*/ #include<stdio.h> int main () { int a[ 10 ],i,sum = 0 ; float av; printf( "enter elements of an aaray: " ); for (i = 0 ;i < 10 ;i ++ ) scanf( "%d" , & a[i]); for (i = 0 ;i < 10 ;i ++ ) sum = sum + a[i]; printf( "sum=%d" ,sum); av = sum / 10 ; printf( "average=%.2f" ,av); return 0 ; } Output: enter elements of an array : 4 4 4 4 4 4 4 4 4 4 sum = 40 average = 4.00 /*Program to find the maximum no. in an array.*/ #include<stdio.h> void main () { int a[ 5 ],max,i; printf( "enter element for the array: " ); for (i = 0 ;i < 5 ;i ++ ) scanf( "%d" , & a[i]); max = a[ 0 ]; for (i = 1 ;i < 5 ;i ++ ) { if (max < a[i]) max = a[i]; } printf( "maximum no= %d" ,max); } Output: enter elements for array : 5 4 7 1 2 maximum no = 7 /*Swapp

Newsboat RSS Reader

Let me tell what is rss reader then i will explain about newsboat,. RSS stands for Rich Site Summary. Simply it is way to subscribe to webpages and when new article is published you can see through the feeds. you get the idea Newsboat is a terminal rss reader which is simple, easy to use and highly customizable how to find rss feed link ?                                   simple trick that i used to find rss feeds in a website check for rss image like above [OR] Right click the website -> view page souce and search for rss copy the link and paste it in urls file in the .config/newsboat/urls (for linux and mac) RSS feeds from twitter: https://twitrss.me/twitter_user_to_rss/?user=<USERNAME> https://www.twitrss.me/twitter_search_to_rss/?term=<SEARCH TERM> example: https://twitrss.me/twitter_user_to_rss/?user=Hytale https://www.twitrss.me/twitter_search_to_rss/?term=Hytale RSS feeds from youtube: https://www.youtube.com/feeds/videos.xml?channel_id

Ecosia

ECOSIA - A Green search engine “ Ecosia donates 80% profits to planting trees” Site: www.ecosia.org Lauched on 7 th December 2009 and created by Christian Kroll available in more than 26 language. It is located in Berlin, Germany.It is also called as CO2-neutral company.Ecosia has donated to different tree-planting programs. Until December 2010 Ecosia’s donations went to a program by WWF Germany that protected the Juruena-National park in the Amazonas. In order to make sure the protection was kept up, the program also drew up and financed plans with timber companies and the  local communities. According to B-labs, as of January 2015, "In donating 80 percent of its ad revenue, the search engine has raised over $1.5 million for rainforest protection since its founding in December 2009." According to Ecosia, by 2015, the search engine had almost 2.5 million active users, and searches through it had resulted in more than 2 million trees being planted.Since October 201