Trunajaya's North Coast offensive

After his victory at the Battle of Gegodog (October 1676) in northeast Java, the Madurese rebel leader Trunajaya proceeded westwards to conquer Mataram Sultanate's remaining towns on the north coast of Java (also known as the Pasisir, today part of Indonesia). By January 1677, nearly all coastal towns from Surabaya to Cirebon (except Jepara) were taken.

Background
The Trunajaya rebellion began in 1674 as Trunajaya's forces conducted raids against the cities under Mataram control. In 1676, a rebel army of 9,000 invaded East Java from their base in Madura, and took Surabaya – the principal city of East Java – shortly after. Mataram King Amangkurat I sent a large army to oppose him under the Crown Prince (later Amangkurat II), but this army was decisively defeated on 13 September at the Battle of Gegodog in northeast Java. After Gegodog, the Javanese north coast was open to Trunajaya's forces.

Offensive
The rebel forces quickly proceeded westwards after the victory. The Javanese northern coastal region – also known as the Pasisir – contained many trading towns, such as Surabaya (already taken by Trunajaya before Gegodog), Tuban, Juwana, Pati, Jepara, Semarang and Kendal.

Battle of Tuban (1676)
In 1676, the rebels met Mataram forces in battle. The rebels defeated the Mataram forces and created an opportunity to capture Surabaya, a coastal city in East Java.

Capture of Surabaya (1676)
After the Battle of Tuban, the rebels went to Surabaya and fought in battles against Mataram forces. The rebels succeeded in defeating the Mataram forces and captured Surabaya.

Fire of Gresik (1676)
After the Mataram forces withdrew from East Java, the rebels launched an offensive in the coastal city in Java. Also in Gresik, the rebels initiated a battle against the Dutch and succeeded in expelling them, then the rebels burned the city.

Fire of Jepara (1676)
After the battles in Gresik, rebels fought battles against the Dutch in Jepara and succeeded in defeating the Dutch, then burned the city. But the victory did not last long, because Dutch and Mataram forces expelled the rebels.

Fire of Cirebon (1676)
This battle was important because the rebels captured Cirebon from Dutch forces, and they also burned and looted the city.

Trunajaya's forces met their first significant resistance in Jepara. In response to the rebellion, Amangkurat had installed a military man, Angabei Wangsadipa as governor in Jepara overseeing the entire northern coast. Subsequently, the town's defenses had been reinforced and additional cannons had been placed. Jepara's defender also had help from a Dutch East India Company (VOC) force of 200 men, who were reinforced by sea "just in time". They arrived there on 20 November 1676 and began besieging the city. The joint Mataram-VOC defense, as well as with quarrel between the Madurese and Makassarese elements of the attackers, caused the attack to ultimately fail.

After failing to take Jepara, Trunajaya's captains – whose forces were augmented by Javanese defectors eager for booty – attacked other towns along the coast. The attacks were made easy because many towns had their fortifications dismantled during or after their conquest by Mataram's Sultan Agung about five decades before. Trading-towns were laid in ruin and ships were taken over to carry out further attacks. According to H. J. de Graaf, Mataram troops conducted "courageous" defenses of Kudus and Demak, but they ultimately fell. On 5 January 1677, Trunajaya reached as far west as Cirebon and took the town, after other coastal towns (except Jepara) had been taken or forced to acknowledge Trunajaya's authority. VOC forces in their Batavia headquarters prevented a further westward advance.